vi rm.sh
#! /bin/bash
##linux删除
huishou=~/.temp
(($#==0)) && { echo "No paraments!";exit 1; }
if [ ! -d $huishou ]; then
mkdir $huishou
fi
for i in $*
do
if test -e $i
then
cd $(dirname $i)
mv -f $(basename $i) $huishou/$(find $(pwd) -maxdepth 1 -name $(basename $i) | tr "/" "=")
cd -
else
echo "$i:No such file or directory!"
fi
done
vi mv.sh
#! /bin/bash
#linux恢复
cd ~/.temp
list=$(for i in $*; do ls |grep "\<$i\>"; done)
(($#==0)) && { list=$(ls|grep ""); }
for j in $list
do
file=$(echo $j | tr "=" "/")
mv $j ${file%/*}/${file##*/}
done
#添加自动任务自动删除临时回收站之前的文件 避免造成文件过大。
cat>renwu.sh<<EOF
#!/bin/bash
ntpdate cn.pool.ntp.org
find ~/.temp -mtime +30 -type f -name *.sh[ab] -exec rm -f {} \;
echo ‘* 1 * * * /bin/bash /home/renwu.sh‘ >>/var/spool/cron/root
service crond restart
EOF
[root@apple home]# chmod 777 rm.sh
[root@apple home]# chmod 777 mv.sh
[root@apple home]# ls
apple mv.sh renwu.sh rm.sh test
[root@apple home]# ./rm.sh test/
/home
[root@apple home]# ls
apple mv.sh renwu.sh rm.sh
[root@apple home]# ls ~/.temp/
=home=test
[root@apple home]# ./mv.sh test
[root@apple home]# ls
apple mv.sh renwu.sh rm.sh test本文出自 “浩子的▁运维笔录ヽ” 博客,请务必保留此出处http://chenhao6.blog.51cto.com/6228054/1551030
原文地址:http://chenhao6.blog.51cto.com/6228054/1551030