国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

刪除文件跟恢復(fù)文件系列

2024-07-21 02:35:18
字體:
供稿:網(wǎng)友

  這一共有三個腳本,他們是一套的
  1)del:刪除文件,其實是把它移動到/trash/$user/下,不同的用戶有不同的存放目錄,同時用該目錄下的.record文件記錄文件原來的路徑,刪除時間,以備恢復(fù)只用。
  2)recover:恢復(fù)文件,通過.record文件找到足夠的信息,從而把它恢復(fù)
  3)erase:這個是徹底的刪除文件,從/trash/$user/目錄下,相當(dāng)于windows下的清空回收站。
  為了安全,這個腳本是要在/trash/$user/目錄下運行。
  
  以下是這三個腳本
  del:
  
  
  源碼:--------------------------------------------------------------------------------
  #!/bin/bash
  #move the file(s) to the /trash/~ instead of deleting.
  #Author: pupilzeng
  #E-mail: shixinzeng@sjtu.edu.cn
  USER=`whoami`
  TRASH=/trash/$USER
  RECORD=/trash/$USER/.record #record file
  ORIG=`pwd`
  DATE=`date +%T---%Y/%m/%d`
  
  Usage ()
  {
   echo "Usage: `basename $0` file(s)"
  }
  
  if [ "$1" = "-h" -o "$1" = "--help" ];then
   Usage
   exit 0
  fi
  if [ $# -le 0 ];then
   Usage
   exit 1
  fi
  
  if [ ! -d $TRASH ];then
   mkdir -p $TRASH
  fi
  
  for i in "$@"
   do
   if [ -w "$i" ];then
   mv "$i" $TRASH
   if [ $? -ne 0 ];then
   echo "Something wrong occurred while delete file $i"
   #but now i won't exit,because there may be other files to be deleted!
   else
   #now write the record file
   if [ "`dirname "$i"`" = "." ] #relative path
   then
   echo -e "$PWD/`basename "$i"`/t/t$DATE ">>$RECORD
   else
   echo -e ""$i" /t/t$DATE">>$RECORD
   fi
   fi
   else
   echo "You have not enough permission to delete $i!"
   fi
   done
  exit 0
  --------------------------------------------------------------------------------
  
  
  recover:
  
  源碼:--------------------------------------------------------------------------------
  #!/bin/bash
  #recover
  #Author: pupilzeng
  #E-mail: shixinzeng@sjtu.edu.cn
  #To recover the removed file(s) by script myrm
  USER=`whoami`
  TRASH=/trash/$USER
  RECORD=$TRASH/.record
  TEMP=$TRASH/.temp
  Usage ()
  {
   echo "Usage:`basename $0` file(s)"
  }
  if [ "$1" = "-h" -o "$1" = "--help" ];then
   Usage
   exit 0
  fi
  
  for i in "$@"
  do
   DEST=`grep "$i" $RECORD awk '{ PRint $1}'`
   mv -f "$i" $DEST
  
   if [ $? -ne 0 ];then
   echo "Something occurred!"
   exit 1
   else
   echo "Recovered $DEST"
   #remove record from $RECORD
   grep -v "$i" $RECORD >$TEMP
   mv -f $TEMP $RECORD
   fi
  done
  exit 0
  --------------------------------------------------------------------------------
  
  
  erase:
  
  源碼:--------------------------------------------------------------------------------
  #!
/bin/bash
  #erase
  #Author: pupilzeng
  #E-mail: shixinzeng@sjtu.edu.cn
  #erase the files in trash that you are sure they needn't at all.
  #for assurance,you should do it in /trash/user Directory.
  Usage ()
  {
   cat <   Usage:`basename $0` [Option] file(s)
   Options:
   -f :don't prompt before erase files
  END
  }
  
  USER=`whoami`
  TRASH=/trash/$USER
  RECORD=$TRASH/.record
  FORCE=no
  TEMP=$TRASH/.temp
  
  if [ $# -lt 1 ]
  then
   echo "Wrong parameters"
   Usage
   exit 1
  fi
  
  if [ $PWD != $TRASH ]
  then
   echo "you should do it in $TRASH directory!"
   exit 1
  fi
  
  if [ "$1" = "-h" -o "$1" = "--help" ]
  then
   Usage
   exit 0
  fi
  
  if [ "$1" = "-f" ];then
   FORCE=yes
   shift
  fi
  
  for i in "$@"
  do
   ANS=no
   if [ $FORCE = "yes" ];then
   rm -fr "$i"
   else
   echo -n "Do you really wanna erase "$i"? Yes[No]:"
   read ANS
   case $ANS in
   "Y""y""Yes""yes")
   rm -fr "$i"
   ;;
   *)
   continue
   ;;
   esac
  
   fi
   if [ $? -eq 0 ];then
   #now remove the records
   grep -v "$i" $RECORD >$TEMP
   mv -f $TEMP $RECORD
   fi
  done
  exit 0

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 沙雅县| 尼木县| 马龙县| 临泉县| 永昌县| 康定县| 西平县| 青川县| 延寿县| 长顺县| 洛浦县| 陆丰市| 银川市| 临安市| 扶绥县| 汉源县| 定日县| 巨野县| 祁门县| 沙河市| 南涧| 宜州市| 仪陇县| 穆棱市| 米林县| 新绛县| 资中县| 富顺县| 龙胜| 南昌县| 平果县| 平昌县| 虹口区| 浦东新区| 大城县| 长武县| 卢湾区| 岳阳市| 图木舒克市| 郁南县| 宾川县|