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 | xargs rm -rf
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

wKioL1QRD5jiXHPYAAG7xFk_MBw457.jpg


wKioL1QRELbyaE4eAADJDFdfRPg633.jpg


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值