#作者:閆曉峰
#E-mail:xiaofeng_yan2004@126.com
#將下列的代碼添加到使用者下的.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
}