将linux下的rm改为mv,使用zsh终端

参考这篇文章,文章来代码是:

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目录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值