shell编程之实现windows回收站功能分享

2019-09-23 09:42:22王旭

  fi
 fi
}

#rm -r
function rmr()
{
 local filename=$(basename $from2)
 local dirname=$(dirname $from2)

 jug_cur $dirname
 if [ $JUG -eq 0 ];then
  dirname=$var_pwd
 elif [ $JUG -eq 1 ];then
  dirname=$var_father
 fi 


 if [ "$from2" = "." -o "$from2" = ".." ];then
  echo "rm: cannot remove directory: '$from2'"
 elif [ -e "$from2" ];then
  echo "$dirname:$filename:$random:$(date +%Y-%m-%d.%T)" >> $mvlog
  mv "$from2" "$trash/$filename:$random"
 else
  file_null $from2
 fi
}

#rm -rf
function rmrf()
{
 local filename=$(basename $from2)
 local dirname=$(dirname $from2)

 jug_cur $dirname
 if [ $JUG -eq 0 ];then
  dirname=$var_pwd
 elif [ $JUG -eq 1 ];then
  dirname=$var_father
 fi 


 if [ "$from2" = "." -o "$from2" = ".." ];then
  echo "rm: cannot remove directory: '$from2'"
 elif [ -e "$from2" ];then
  echo "$dirname:$filename:$random:$(date +%Y-%m-%d.%T)" >> $mvlog
  mv "$from2" "$trash/$filename:$random"
 else
  :
 fi
}

#rm -ir
function rmir()
{
 local filename=$(basename $from2)
 local dirname=$(dirname $from2)

 jug_cur $dirname
 if [ $JUG -eq 0 ];then
  dirname=$var_pwd
 elif [ $JUG -eq 1 ];then
  dirname=$var_father
 fi 


 if [ -e "$from2" ];then
  if [ -d "$from2" ];then
   echo -n "rm: remove directory '$from2'?"
  else
   echo -n "rm: remove regular file '$from2'?"
  fi

  read answer
  if [ "$answer" = 'y' -o "$answer" = 'Y' ];then
   echo "$dirname:$filename:$random:$(date +%Y-%m-%d.%T)" >> $mvlog
   mv "$from2" "$trash/$filename:$random"
  fi
 else
  if [ ! -e $from2 ];then
   file_null $from2
  fi
 fi

}

#清空回收站
function rmc()
{
 /bin/rm -rf $trash
}

function rml()
{
 local tmp=$(mktemp /tmp/tfile.XXXXXX)
 clear

 if [ ! -d "$trash" ];then
  mkdir $trash
 fi

 if [ ! -f "$mvlog" ];then
  touch $mvlog
 fi
 line=$(cat -n $mvlog | awk -F: '{print $1, "FileName:"$2, "Time: "$4":"$5":"$6}')
 linecount=$(cat $mvlog | wc -l)
 echo -e "$line"
 echo
 echo
 echo "[$linecount] Please enter the file you want to restore (replaced with the line number)"
 printf "RowNumber: "
 read answer
 if [ "$answer" = 'q' -o "$answer" = 'Q' -o "$answer" = "" ];then
  :
 else
  printf "Please confirm (Y/N): "