码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2018-08-23 17:00:48      阅读:649      评论:0      收藏:0      [点我收藏+]

标签:read   src   递归遍历   blog   51cto   directory   input   技术   The   

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脚本递归遍历某个目录下的所有文件并移动到某个指定的目录中

标签:read   src   递归遍历   blog   51cto   directory   input   技术   The   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!