linux下回收站
========================删除程序==========================
#! /bin/bash currpath=`pwd` (($#==0)) && { echo "No paraments!";exit 1; } #show the contents in ~/.trash if [ $# = 1 -a $1 = '-s' ] ; then #ls ls ~/.trash exit fi if [ $# = 1 -a $1 = '-l' ] ; then #ls -l ls -l ~/.trash exit fi #del the contents in ~/.trash if [ $# = 1 -a $1 = '-q' ] ; then rm -fr ~/.trash/* exit fi for i in $* do cd $currpath ################## cd `dirname $i` #$tmpbasename=`basename $i` echo $tmpbasename #if [ "\*" = $tmpbasename ] ; then # `ls|del` #fi ################## if [ ${i:0:2} = "./" ] ; then i=${i:2} fi cd $currpath if [ -f $i -o -d $i ] ; then cd `dirname $i` #get the file name tmpname=$(find $(pwd) -maxdepth 1 -name $(basename $i) | tr "/" "=") #at home path ,if .trash is not a directory ,then create it cd ~ if [ ! -d .trash ] ; then mkdir .trash fi #test if the file already exists cd ~/.trash if [ -f $tmpname ] ; then echo "exist!" nowtime=`date "+%Y%m%d%H%M%S"` tmpname=${tmpname}_${nowtime} fi #change into the current path cd $currpath mv -f $i ~/.trash/${tmpname} else echo "$i: No such file or directory!" fi done ==================恢复删除文件====================== #! /bin/bash ######################################################### # PRGM : undel ######################################################### currpath=`pwd` ######################################################### # # whether the num of arguments is 0 # ######################################################### if [ $# = 0 ] ; then echo "No arguments" exit 1 fi ########################################################## for i in $* do tmp2path=`dirname $i` if test "." = `dirname $i` #the current path is . then echo 1 tmppath=`pwd| tr "/" "=" ` elif test "./" = ${tmp2path:0:2} #the path is beginned with ./ then echo 2 tmppath3=`echo ${tmp2path:1}` tmppath="`pwd`$tmppath3" elif test "/" = ${tmp2path:0:1} #the path is beginned with not . and not ./ then echo 4 tmppath=`dirname $i | tr "/" "=" ` else echo 3 tmppath3="/${tmp2path}" tmppath="`pwd`$tmppath3" #the path is beginned with / fi tmppath=`echo $tmppath | tr "/" "="` cd $(dirname $i) #get the file name tmpname="${tmppath}=`basename $i`" echo $tmpname cd ~/.trash if [ ! -f $tmpname -a ! -d $tmpname ] ; then echo "No such file in the .trash!"; continue fi tmppath2=` echo $tmpname | tr "=" '/' ` mv $tmpname `basename $i` mv `basename $i` `dirname $tmppath2` cd $currpath echo "${tmpname} recover successfully... " done =====================文档======================= 1)del -l show the detail of files in ~/.trash -s show the name of files in ~/.trash only -f del the files as `rm -f` -q clean ~/.trash 2)undel undel f1 f2 f3 /root/f5 3)del & undel e.g. args stat recover stat stat ------------------ + --------------- + ----------------------------- + -------- del a.txt OK undel a.txt OK del a.txt b.txt OK undel a.txt b.txt OK del /root/a.txt OK undel /root/a.txt OK del lib/* OK undel lib/a.txt undel lib/b.txt OK .... del ./lib/* OK undel lib/a.txt undel lib/b.txt OK .... del lib/a.txt lib/b.txt OK undel lib/a.txt undel lib/b.txt OK del ./lib/a.txt OK undel ./lib/a.txt OK 4)readme if there is a file which name and directory are as same as the currentfile's , and create a file as =home=cnscn=a.txt_20041129000248.If you want recover it can cp it to /home/cnscn/a.txt (Of course there must not be a.txt in /home/cnscn now) =====================示例======================= [root@localhost ~/bin]$ pwd /home/user/cnscn/bin [root@localhost ~/bin]$ ls a.txt b.txt del undel [root@localhost ~/bin]$ ls /root/a.txt /root/a.txt [root@localhost ~/bin]$ ls ~/.trash [root@localhost ~/bin]$ del a.txt /root/a.txt [root@localhost ~/bin]$ ls ~/.trash =home=user=cnscn=bin=a.txt =root=a.txt [root@localhost ~/bin]$ ls a.txt [root@localhost ~/bin]$ ls /root/a.txt [root@localhost ~/bin]$ undel a.txt /root/a.txt =home=user=cnscn=bin=a.txt recover successfully... =root=a.txt recover successfully... [root@localhost ~/bin]$ ls ~/.trash [root@localhost ~/bin]$ 附件:
del.txt (2 K) 下载次数:0
附件:
undel.txt (2 K) 下载次数:0
» 相关连接:
|
» 本栏目最新帖:
» 网站最新帖:
» 精华帖:
» 热点帖:
|