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

前端之家收集整理的这篇文章主要介绍了如何防止命令显示在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

原文链接:https://www.f2er.com/bash/390747.html

猜你在找的Bash相关文章