害怕用 rm -rf?不如试试这个
Linux 中 rm -rf /
这个命令大家应该不陌生。
为了减少误操作,网上有很多方案
方案 1 (不推荐)
- 起别名
alias rm='rm -i'
删除都需要确认
这种方式治标不治本,因为主动权还是在我手中。
方案 2 (不推荐)
但是遇到目录或者相同文件没办法处理历史文件,且脚本太复杂,本人水平有限难以找到优雅处理方式。
方案 3 (强烈推荐)
使用 trash-cli
命令代替 rm
trash-cli 的基本命令:
1 2 3 4 5
| trash-put trash-empty trash-list trash-restore trash-rm
|
在你的 shell 添加 alias rm="trash-put"
删除东西别怕,正常 rm 就行。
使用方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| /opt/test ---------------------------------------------------------------------------------------------------------------- /opt/test total 0 -rw-r--r-- 1 root root 0 Feb 23 22:40 testFile ---------------------------------------------------------------------------------------------------------------- /opt/test ---------------------------------------------------------------------------------------------------------------- /opt/test total 0 ---------------------------------------------------------------------------------------------------------------- /opt/test 2025-02-23 22:40:25 /opt/test/testFile ---------------------------------------------------------------------------------------------------------------- /opt/test /root/.local/share/Trash ├── files │ └── testFile └── info └── testFile.trashinfo
2 directories, 2 files ---------------------------------------------------------------------------------------------------------------- /opt/test 0 2025-02-23 22:40:25 /opt/test/testFile What file to restore [0..0]: 0 ---------------------------------------------------------------------------------------------------------------- /opt/test ---------------------------------------------------------------------------------------------------------------- /opt/test /root/.local/share/Trash ├── files └── info
2 directories, 0 files ---------------------------------------------------------------------------------------------------------------- /opt/test total 0 -rw-r--r-- 1 root root 0 Feb 23 22:40 testFile ---------------------------------------------------------------------------------------------------------------- /opt/test
|