我只是alias rm="rm -I"
为了防止意外rm
命令而创建的。
-I prompt once before removing more than three files, or when removing recursively.
Less intrusive than -i, while still giving protection against most mistakes
Run Code Online (Sandbox Code Playgroud)
但它不起作用。我在使用时没有得到任何提示rm -rf
如果你再次阅读帮助,你会看到它说的是previous --interactive
。这意味着您可以-I
在所有其他参数之后添加一个(例如在行尾),它会再次受到尊重!
要做到这一点,您需要一个函数而不是别名,但只需将其粘贴在您的.bashrc
(et al) 中的某个位置,您就大功告成了:
function rm { /bin/rm "$@" -I; }
Run Code Online (Sandbox Code Playgroud)
一种可能比使用trash-cli
'strash-put
命令更安全的方法。它将把东西放在你帐户的垃圾目录中,可以正常查看/恢复/清空。它还具有 dummy -r
, -f
and,-i
参数,因此它可以实现完美的别名:
alias rm="trash-put"
Run Code Online (Sandbox Code Playgroud)
这里的问题是-f
makerm
忽略任何交互式命令:
`-f'
`--force'
Ignore nonexistent files and missing operands, and never prompt
the user. Ignore any previous `--interactive' (`-i') option.
Run Code Online (Sandbox Code Playgroud)
来源: info coreutils 'rm invocation'