cat recursive.sh
#!/bin/sh
read -p "input path:" FilePath
function getAllfiles(){
for file in ls $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/目录下的所有文件都移动到/bak_file/目录中
2.1,先查看下/test/目录的结构
2.2,执行脚本,移动/test/目录下的所有文件
sh recursive.sh
2.3,查看/bak_file/目录
2.4,测试成功,完毕!