linux 意外删除与恢复

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

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。