现在 Linux 上有啥危险命令提示的工具吗

9 天前
 smdbh
10 多年终于遇到来了,手滑敲太快,来了个全盘操作。。。。
想问下,现在有没有 shell 的插件,或工具,能拦截命令,在对全盘有写操作的时候,进行提示。最好基于 zsh ,bash
5397 次点击
所在节点    Linux
62 条回复
honus
9 天前
养成日常不用 root 用户的习惯吧
lstz
9 天前
上 zsh
abcde123456789
9 天前
终于理解为啥不推荐用 root 了
SayHelloHi
9 天前
借楼问下 有没有检查安全更新的脚本 可以一键安装安全更新包 😁 求一个
smdbh
9 天前
@abcde123456789 ,不是 root , 在制作 rootfs ,sudo 了, 两个目录没分清
xmai
9 天前
搞个函数包装一下原始命令,比如包装一下 rm 命令,

```
rm() {
echo “Are you sure you want to delete? (y/n)”
read answer
if [ “$answer” == “y” ]; then
command rm “$@”
else
echo “Delete aborted!”
fi
}
```

执行 rm 命令之前,添加了一个询问用户是否确认删除的逻辑。只有在用户确认删除时,才会执行原始的 rm 命令。
smdbh
9 天前
@lstz ,就是 zsh ,是有啥插件吗,默认和 bash 没区别,都直接执行
xmai
9 天前
你硬要上插件,也是有解决方案,这个插件可以拦截任何有风险的 shell 命令(默认或由您定义)并提示进行双重验证
https://github.com/kaplanelad/shellfirm
Jinnrry
9 天前
我们公司 ssh 服务器要经过跳板机,跳板机会记录所有操作命令,同时会做命令审计,如果你敲个 rm /或者导出敏感文件日志啥的,立马就中断要求提审批单
Jiceburger
9 天前
@xmai 额,也许 alias rm="rm -i" 更简单一些?
xubeiyou
9 天前
让运维隔段时间做备份。。。我当前小公司就这么做的
huangmingyou
9 天前
我现在习惯把危险命令写到临时文件 file, 检查确认后用 bash file 执行。
villivateur
9 天前
$ rm --help
Usage: rm [OPTION]... [FILE]...
Remove (unlink) the FILE(s).

-f, --force ignore nonexistent files and arguments, never prompt
-i prompt before every removal
-I prompt once before removing more than three files, or
when removing recursively; less intrusive than -i,
while still giving protection against most mistakes
--interactive[=WHEN] prompt according to WHEN: never, once (-I), or
always (-i); without WHEN, prompt always
--one-file-system when removing a hierarchy recursively, skip any
directory that is on a file system different from
that of the corresponding command line argument
--no-preserve-root do not treat '/' specially
--preserve-root[=all] do not remove '/' (default);
with 'all', reject any command line argument
on a separate device from its parent
-r, -R, --recursive remove directories and their contents recursively
-d, --dir remove empty directories
-v, --verbose explain what is being done
--help display this help and exit
--version output version information and exit

我觉得 -I 的那一坨够用了
smdbh
9 天前
@xmai @villivateur , 是个方法,但我这次翻车的是 chmod ,把权限搞崩了,导致 sudo 等命令没法用了
llh880808
9 天前
我一直在推荐同事修改键入 rm 命令的顺序,比如 rm -rf /some/nouse/path ,常规顺序是从左到右,我建议先输入/some/nouse/path ,然后 ctrl-a 回到开头再输入 rm -rf
从左到右的顺序,我一直担心路径还没输入完,就不小心按到回车的事情发生
chenjiasange
9 天前
我犯贱的时候,不小心直接把整个 rm / 整个删除了。。。。
xiebaiyuan
9 天前
举例子类似 rm 给 alias 到 trash 命令.

cp alias 到 cp -i 这种..

另外别用 root..后患无穷
w4ngzhen
9 天前
更加推荐 rm 别名到 cp 等,把删除的内容放到临时目录下。至于 rm 加上确认 prompt ,可能短期有用,但是长期很容易养成一路 yes 的习惯,实际上没啥大用处。
wenxueywx
9 天前
@llh880808 使用习惯不好,rm -rf 不要连用,要用 rm /xxxxx -rf
wushenlun
9 天前
@xmai 用久了就会习惯性 -y

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1051025

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX