加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何防止命令显示在bash历史记录中?

发布时间:2020-12-15 16:18:51 所属栏目:安全 来源:网络整理
导读:有时,当我运行命令像rm -rf XYZ,我不希望这被记录在bash历史记录,因为我可能不小心再次通过reverse-i-search运行相同的命令。有没有好的方法来防止这种情况发生? 如果您将HISTCONTROL设置为ignoreboth(通常是默认设置),则具有前导空格字符的命令不会存
有时,当我运行命令像rm -rf XYZ,我不希望这被记录在bash历史记录,因为我可能不小心再次通过reverse-i-search运行相同的命令。有没有好的方法来防止这种情况发生?
如果您将HISTCONTROL设置为ignoreboth(通常是默认设置),则具有前导空格字符的命令不会存储在历史记录中(以及重复的)。

例如:

$ echo test1
$  echo test2
$ history | tail -n2
 1015  echo test1
 1016  history | tail -n2

这里是男人bash说:

HISTCONTROL

A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ignorespace,lines which begin with a space character are not saved in the history list. A value of ignoredups causes lines matching the previous history entry to not be saved. A value of ignoreboth is shorthand for ignorespace and ignoredups. A value of erasedups causes all previous lines matching the current line to be removed from the history list before that line is saved. Any value not in the above list is ignored. If HISTCONTROL is unset,or does not include a valid value,all lines read by the shell parser are saved on the history list,subject to the value of HISTIGNORE. The second and subsequent lines of a multi-line compound command are not tested,and are added to the history regardless of the value of HISTCONTROL.

也可以看看:

> Why is bash not storing commands that start with spaces?在unix SE
> Why does bash have a HISTCONTROL=ignorespace option? at unix SE

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读