文件目录删除脚本(&D)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了文件目录删除脚本(&D)相关的知识,希望对你有一定的参考价值。

Modified a little bit to make it easier to change the location of the recycle bin.
  1. #!/bin/bash
  2. #
  3. # This script is to be called by an alias of the rm command
  4. # e.g. using the entry...
  5. # alias rm='sh /home/user1/my_scripts/rm_replacement.sh'
  6. # in your $HOME/.profile or $HOME/.bashrc file
  7. #
  8. # It will move rm files to /home/user1/.RecycleBin
  9. # You need to create the directory /home/user1/.RecycleBin if
  10. # it doesn't already exist
  11. #
  12. # If a file/directory with the same name already exists in the
  13. # RecycleBin, the file/directory already in the RecycleBin
  14. # will be renamed taging "_X" on to the end where
  15. # X is an incremental number and then the newly rm'd
  16. # file/directory will be copied into the RecycleBin
  17. #
  18. # Consequently the latest version of the file will be its normall
  19. # name, without any extension.
  20.  
  21. RM_OPT=""
  22. FILES=""
  23. VERBOSE="n"
  24. FORCE="n"
  25. VOLUME="/home/user1"
  26.  
  27. while [ "$1" ]; do
  28. case "$1" in
  29. "-v") VERBOSE="y" ;;
  30. "-f") FORCE="y" ;;
  31. "--help" | "-h")
  32. echo "You are running a replacement for rm called by an alias"
  33. echo "Usage rm [options] file1 file2 ..."
  34. echo
  35. echo "Moves the files to /volume1/RecycleBin. Files can be either files or"
  36. echo "directories."
  37. echo
  38. echo "Options:"
  39. echo " -v verbose mode"
  40. echo " -h, --help this help message"
  41. echo " --help-rm help message of /bin/rm"
  42. echo " -f force processing with the normal rm command (/bin/rm)"
  43. echo " All other options are ignored when moving files. When removing"
  44. echo " permanently, these options are passed to /bin/rm"
  45. echo
  46. exit 0
  47. ;;
  48. "--help-rm")
  49. /bin/rm --help
  50. exit 0
  51. ;;
  52. -*) RM_OPT=$RM_OPT" "$1 ;;
  53. *)
  54. if [ "$VERBOSE" = "y" ]; then
  55. echo $1
  56. fi
  57. if [ "$FORCE" = "y" ]; then
  58. /bin/rm -f $RM_OPT $1
  59. else
  60. if [ -e "$1" ]; then
  61. if [ -e "$VOLUME/.RecycleBin/$(basename $1)" ]; then
  62. version=2
  63. while [ -e "$VOLUME/.RecycleBin/$(basename $1)_$version" ]; do
  64. let version=$version+1
  65. done
  66. mv "$VOLUME/.RecycleBin/$(basename $1)" "$VOLUME/.RecycleBin/$(basename $1)_$version"
  67. fi
  68. mv "$1" "$VOLUME/.RecycleBin"
  69. fi
  70. fi
  71. ;;
  72. esac
  73. shift
  74. done

以上是关于文件目录删除脚本(&D)的主要内容,如果未能解决你的问题,请参考以下文章

常用python日期日志获取内容循环的代码片段

CMD 删除脚本

windows的bat脚本

linux下遍历目录和文件,删除过期天数目录或文件shell脚本

批处理脚本下文件与文件夹的操作

windows 定时删除N天前日志脚本