Linux 使用 trash-cli 防止误删除

Spoony 54.35m2019-12-211320 次点击1 人感谢
玩过Linux的同学应该都知道这个要命的命令,此命令一出,系统几乎废了。
rm -rf /

虽然一再强调rm的时候要注意,但是还是会有同学犯错误删文件,有什么办法能够减少此类事情的发生呢?

trash-cli 实现了类似回收站的功能,以后删除的时候就有了后悔药。

https://github.com/andreafrancia/trash-cli

# 安装
trash-cli的安装很简单
cd /tmp
git clone https://github.com/andreafrancia/trash-cli
unzip trash-cli-master.zip
cd trash-cli-master
python setup.py install
安装成功后我们的系统就有了以下工具

➜ ~ ll /usr/bin/|grep trash
-rwxr-xr-x 1 root root 123 5月 28 19:38 trash
-rwxr-xr-x 1 root root 125 5月 28 19:38 trash-empty
-rwxr-xr-x 1 root root 124 5月 28 19:38 trash-list
-rwxr-xr-x 1 root root 123 5月 28 19:38 trash-put
-rwxr-xr-x 1 root root 127 5月 28 19:38 trash-restore
-rwxr-xr-x 1 root root 122 5月 28 19:38 trash-rm

# 功能说明
trash == trash-put == 删除
trash-empty 清空
trash-list 列出回收站
trash-restore 恢复文件
trash-rm 删除回收站中指定文件

# 如何使用
替换命令
为了安全着想,我们先将rm命令替换为trash
vim /etc/bashrc
添加以下内容,替换系统删除命令。

根据作者的README文件,建议还是轻易不要把rm做替换,下面的替换作废。
alias log='cd /var/log'

安全删除
alias rm='trash'

列出回收站
alias rl='trash-list'
收藏 ♥ 感谢
暂无回复

登录注册 后可回复。




› 相关内容关注微信公众号