历史记录

历史记录

我通常在登录时输入密码MySQL. 如何避免mysql -u root -pPassword历史

答案1

在命令前留一个空格。

这会起作用,因为默认情况下,变量$HISTCONTROL包含ignoreboth这意味着ignorespaceignoredupsignorespace有前导空格时,bash 不会将命令保存在历史记录中。

man 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.

如果您想要从 Bash 的历史记录系统范围内排除某个命令,请将以下内容添加到您的/etc/bash.bashrc

HISTIGNORE='mysql*'

这将排除以 开头的任何命令mysql

执行source /etc/bash.bashrc以应用更改。

来源:https://unix.stackexchange.com/questions/32460/clusion-some-of-the-commands-from-being-getting-stored-in-bash-history

相关内容