文件目录删除脚本(&D)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了文件目录删除脚本(&D)相关的知识,希望对你有一定的参考价值。
Modified a little bit to make it easier to change the location of the recycle bin.
#!/bin/bash # # This script is to be called by an alias of the rm command # e.g. using the entry... # alias rm='sh /home/user1/my_scripts/rm_replacement.sh' # in your $HOME/.profile or $HOME/.bashrc file # # It will move rm files to /home/user1/.RecycleBin # You need to create the directory /home/user1/.RecycleBin if # it doesn't already exist # # If a file/directory with the same name already exists in the # RecycleBin, the file/directory already in the RecycleBin # will be renamed taging "_X" on to the end where # X is an incremental number and then the newly rm'd # file/directory will be copied into the RecycleBin # # Consequently the latest version of the file will be its normall # name, without any extension. RM_OPT="" FILES="" VERBOSE="n" FORCE="n" VOLUME="/home/user1" while [ "$1" ]; do case "$1" in "-v") VERBOSE="y" ;; "-f") FORCE="y" ;; "--help" | "-h") echo "You are running a replacement for rm called by an alias" echo "Usage rm [options] file1 file2 ..." echo echo "Moves the files to /volume1/RecycleBin. Files can be either files or" echo "directories." echo echo "Options:" echo " -v verbose mode" echo " -h, --help this help message" echo " --help-rm help message of /bin/rm" echo " -f force processing with the normal rm command (/bin/rm)" echo " All other options are ignored when moving files. When removing" echo " permanently, these options are passed to /bin/rm" echo exit 0 ;; "--help-rm") /bin/rm --help exit 0 ;; -*) RM_OPT=$RM_OPT" "$1 ;; *) if [ "$VERBOSE" = "y" ]; then echo $1 fi if [ "$FORCE" = "y" ]; then /bin/rm -f $RM_OPT $1 else if [ -e "$1" ]; then if [ -e "$VOLUME/.RecycleBin/$(basename $1)" ]; then version=2 while [ -e "$VOLUME/.RecycleBin/$(basename $1)_$version" ]; do let version=$version+1 done mv "$VOLUME/.RecycleBin/$(basename $1)" "$VOLUME/.RecycleBin/$(basename $1)_$version" fi mv "$1" "$VOLUME/.RecycleBin" fi fi ;; esac shift done
以上是关于文件目录删除脚本(&D)的主要内容,如果未能解决你的问题,请参考以下文章