rm 删除文件到垃圾箱

#将下列的代码添加到用户下的.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
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值