避免在历史中保持命令

Modified on: Mon, 08 Jul 2019 21:00:02 +0800

我使用bash,我想避免在历史记录中保留一些命令。

  • 是否可以仅对下一个命令执行此操作?
  • 是否可以在整个会话中执行此操作?
作者:Iain,Luc M

最佳答案

我记得另一个答案,这是你问题的实际答案。

如果你在HISTCONTROL中有“ignorespace”,那么bash不会记住任何以空格字符开头的行。它甚至不会出现在当前shell的历史中,更不用说保存到$ HISTFILE。

e.g。我在〜/ .bashrc中导出HISTCONTROL ='ignoreboth:erasedups'

这是来自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.
作者:cas

相关问答

添加新评论