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