如何prevent命令在bash的历史展现出来? [英] How to prevent commands to show up in bash history?
问题描述
有时候,当我运行像室射频XYZ
命令,我不希望这被记录在bash的历史,因为我可能会不小心再次运行相同的命令通过反向我搜索
。是否有prevent这是一个很好的方式发生?
Sometimes, when I run commands like rm -rf XYZ
, I don't want this to be recorded in bash history, because I might accidentally run the same command again by reverse-i-search
. Is there a good way to prevent this from happening?
推荐答案
如果您已经 HISTCONTROL
设置为 ignoreboth
(通常默认设置),命令与一个空格字符将不被存储在历史(以及重复的)。
If you've HISTCONTROL
set to ignoreboth
(which is usually set by default), commands with a leading space character will not be stored in the history (as well as duplicates).
例如:
$ echo test1
$ echo test2
$ history | tail -n2
1015 echo test1
1016 history | tail -n2
下面是男人庆典
说:
HISTCONTROL
HISTCONTROL
值控制命令的方式保存在历史列表中的冒号分隔的列表。如果值列表包括 ignorespace
,以空格字符开头的行不会被保存在历史列表即可。 ignoredups
的值会导致previous历史条目匹配行不会被保存。 ignoreboth
的值是 ignorespace
速记和 ignoredups
。 erasedups
的值会导致所有previous线匹配当前行从历史列表中删除保存在该行之前。在上面的列表中的任何值不被忽略。如果 HISTCONTROL
未设置或不包含有效的值,由shell解析器读取所有线路都保存在历史列表中,受 HISTIGNORE
。多行的组合命令的第二个和后续行没有测试,并添加到历史记录不管价值 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是的bash不存储与空格开头的命令?的在Unix SE
- Why没有庆典有HISTCONTROL = ignorespace选项?在UNIX SE
- Why is bash not storing commands that start with spaces? at unix SE
- Why does bash have a HISTCONTROL=ignorespace option? at unix SE
这篇关于如何prevent命令在bash的历史展现出来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!