首页 > 移动平台 > 详细

用shell脚本递归遍历某个目录下的所有文件并移动到某个指定的目录中

时间:2018-08-23 16:46:53      阅读:257      评论:0      收藏:0      [点我收藏+]
1,先看下脚本
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,测试成功,完毕!

用shell脚本递归遍历某个目录下的所有文件并移动到某个指定的目录中

原文:http://blog.51cto.com/13718210/2163432

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!