参考这篇文章,文章来代码是:
mkdir -p ~/.trash
alias rm=trash
alias r=trash
alias rl='ls ~/.trash'
alias ur=undelfile
undelfile()
{
mv -i ~/.trash/$@ ./
}
trash()
{
mv $@ ~/.trash/
}
cleartrash()
{
read -p "clear sure?[n]" confirm
[ $confirm == 'y' ] || [ $confirm == 'Y' ] && /bin/rm -rf ~/.trash/*
}
可以看出原来作者洗的cleartrash并没有使用,我自己使用alias调用后,发现会在zsh终端里会报错,但是在bash终端里可以运行,而作者用的也是zsh终端,这可能也是他没有调用的原因吧。
read会报错
read: -p: no coprocess
参考这个讨论
修改最终代码如下:
mkdir -p ~/.trash
alias rm=trash
alias r=trash
alias rl='ls ~/.trash'
alias ur=undelfile
alias clrm=cleartrash
undelfile()
{
mv -i ~/.trash/$@ ./
}
trash()
{
mv $@ ~/.trash/
}
cleartrash()
{
echo -n "clear the trash?"
read REPLY
if [[ $REPLY =~ ^[Nn]$ ]]
then
echo "You asked for it..."
fi
if [[ $REPLY =~ ^[Yy]$ ]]
then
/bin/rm -rf ~/.trash/*
fi
REPLY=""
}
用法:
rm 文件名
会把该文件移动到~/.trash目录下
ur 文件名
会把~/.trash目录下的对应文件,移动到 当前目录(执行ur命令时的目录)。
目前不能直接在trash里面恢复文件,就是像windows那种的。因为从当前目录删除其他目录下面的文件,没有想到解决办法,例如在根目录下执行
rm ~/test/test.txt,没想到怎么做。
clrm
清空~/.trash目录