#将下列的代码添加到用户下的.bashrc中,这样这段代码就可以发挥作用了。如果是在终端输入的那么输入代码后退出终端在打开终端,这段代码就生效了。有一部分是参照网上的代码。
#具体功能如下:
#rm
#rm -f
#rm -r
#rm -rf
#rl 查看回收站的内容
#rc 清空回收站
#ur 后面加参数恢复回收站的文件到当前目录下
mkdir -p ~/.trash
alias rm=trash
alias rc=clean_trash
alias rl='ls ~/.trash'
alias ur=undelfile
undelfile()
{
if test -z "$1"
then
echo -e "/E[32;40mPleae input recovery file or directory name"
tput sgr0
else
until [ -z "$1" ]
do
mv -i ~/.trash/$1 ./
shift
done
fi
}
trash()
{
if [ "$1" == "-f" -o "$1" == "-rf" -o "$1" == "-r" ]; then
until [ -z "$2" ]
do
mv $2 ~/.trash/
shift
done
else
mv $@ ~/.trash
fi
}
clean_trash()
{
echo -e "/E[32;40mdo you want to empty Recycle Bin,Please input /"yes/" or /"no/""
read CLEAN
if [ "$CLEAN" == "y" -o "$CLEAN" == "yes" ]; then
/bin/rm -rf ~/.trash/*
echo -e "/E[32;40mRecycle Bin is cleared!"
tput sgr0
else
echo -e "/E[31;40mdon't clean trash"
fi
tput sgr0
}
####################################################################
#修改上述代码,增加如果回收站里已经有了你删除的文件当再次删除同样的文件时,原来的文件将变成文件名+替换的时间。#
####################################################################
#trash funnction
#author: Yan Xiaofeng
mkdir -p ~/.trash
alias rm=trash
alias rc=clean_trash
alias rl='ls ~/.trash'
alias ur=undelfile
#CURRENT_FILE_NUM=`ls -l | wc -l`
#FILE_REMOVED=0
#CURRENT_DIR=`pwd`
#i=0
TRASH=~/.trash
undelfile()
{
if test -z "$1"
then
echo -e "/E[32;40mPleae input recovery file or directory name"
tput sgr0
else
until [ -z "$1" ]
do
mv -i ~/.trash/$1 ./
shift
done
fi
}
trash()
{
if [ "$1" == "-f" -o "$1" == "-rf" -o "$1" == "-r" ]; then
until [ -z "$2" ]
do
if [ -e "$TRASH/$2" ]; then
mv $TRASH/$2 $TRASH/`basename $2`-`date +%F`-`date +%R`-`date +%S`
fi
mv $2 $TRASH
shift
done
else
until [ -z "$1" ]
do
if [ -e "$TRASH/$1" ]; then
mv $TRASH/$1 $TRASH/`basename $1`-`date +%F`-`date +%R`-`date +%S`
fi
mv $1 $TRASH
shift
done
fi
}
clean_trash()
{
read -p "`echo -e "/E[32;40mDo you want to empty Recycle Bin,Please input /"yes/" or /"no/":/E[35;40m"`" CLEAN
# read CLEAN
if [ "$CLEAN" == "y" -o "$CLEAN" == "yes" ]; then
/bin/rm -rf ~/.trash/*
echo -e "/E[32;40mRecycle Bin is cleared!"
tput sgr0
else
echo -e "/E[31;40mDon't clean trash"
fi
tput sgr0
}