Recursively traverse all files in a directory with a shell script and move to a specified directory

Source: Internet
Author: User

1, first look at the script
Cat recursive.sh

#!/bin/sh
Read-p "Input path:" FilePath

function Getallfiles () {
For file inls $FilePath
Do
If [-f $file]
Then
Echo $file
MV $file/bak_file/
Elif test-d $file
Then
echo "-------------------------------->"
CD $file
Filepath=pwd
Getallfiles
Cd..
Echo-e "\033[32m[############ $file is a directory .... #######]\033[0m"
echo "<-------------------------------"
Else
echo "$FilePath is a invalid path"
Fi
Done

}
CD $FilePath
Getallfiles $FilePath

2, test, now say all files in the/test/directory are moved to the/bak_file/directory
2.1, first look at the structure of the next/test/directory

2.2, execute script, move all files under/test/directory
SH recursive.sh
2.3. View the/bak_file/directory

2.4, Test success, complete!

Recursively traverse all files in a directory with a shell script and move to a specified directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.