(OK) find-alter-files.sh——递归
find-alter-files.sh
#!/bin/sh
#注意:每次修改代码前,在/var/www/html/aaa 下面 touch time.txt
#存放修改后的文件 /root/var/www/html/aaa
#newerdir="/root"
function scandir() {
local cur_dir parent_dir workdir newerdir
newerdir="/root"
workdir=$1
cd ${workdir}
if [ ${workdir} = "/" ]
then
cur_dir=""
else
cur_dir=$(pwd)
fi
for dirlist in $(ls ${cur_dir})
do
if test -d ${dirlist};then
cd ${dirlist}
scandir ${cur_dir}/${dirlist}
cd ..
elif test -f ${dirlist};then
#在Linux系统下, 找出新修改的文件,并且,复制到 合适的位置
#注意:每次修改代码前,在/var/www/html/ 下面 touch time.txt
newer=`find ${dirlist} -newer /var/www/html/time.txt`
if [ "${newer}" == "${dirlist}" ];then
tmp_dir=$(pwd)
mkdir -p ${newerdir}${tmp_dir} 2> /dev/null
cp ${newer} ${newerdir}${tmp_dir}
fi
fi
done
}
if test -d $1
then
scandir $1
elif test -f $1
then
echo "you input a file but not a directory,pls reinput and try again"
exit 1
else
echo "the Directory isn't exist which you input,pls input a new one!!"
exit 1
fi