Macos rmtrash
- 安装
brew install rmtrash
- .bashrc或者.zshrc加alias
alias rm='rmtrash'
这样你使用 rm 直接删除的文件就会放到你的用户 .Trash 隐藏文件夹里边,如果误删了可以去这里恢复即可。 rmtrash 可以直接删除文件夹,所以不需要 -r 参数了。
Linux/MacOS通用 safe-rm
安装方法一 clone
git clone https://github.com/kaelzhang/shell-safe-rm ~/.shell-safe-rm
# alias 加入到你的 bashrc or zshrc 里边,默认也是 .Trash(mac) 或者 linux "$HOME/.local/share/Trash/files"
# 如果你想修改默认垃圾桶的路径,直接使用 vim 之类的编辑器修改这个 rm.sh 文件开头的默认路径就可以了
alias rm='~/.shell-safe-rm/bin/rm.sh'
安装方法二 使用过nodejs也可以使用npm安装
npm install -g safe-rm;
# alias 加入到你的 bashrc or zshrc 里边
alias rm='safe-rm'
同样可以做个简单的测试:
# 进入用户主目录,创建一个文件"痛苦的回忆",然后 rm 删除看看
# 之后 cd ~/.Trash 里边就可以找到了
cd
touch 痛苦的回忆
rm 痛苦的回忆
卸载
# First remove the alias line from your ~/.bashrc file, then
npm uninstall -g safe-rm
# Or
make && sudo make uninstall
# Or
sudo sh uninstall.sh
网友评论