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

有时,当我运行命令像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

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...