ilk*_*chu 10
取决于外壳。在 Bash 中,您可以通过以下几种方式控制历史记录:
使用禁用保存历史记录set +o history并重新启用它set -o history(注意倒置的加号和减号)。禁用历史记录后,输入的命令不会保存在历史日志中,但可以使用以前的命令。
通过设置HISTFILE( HISTFILE=~/somehistoryfile)来设置用于保存历史记录的文件。您可以通过使用 取消设置变量来完全禁用它unset HISTFILE。如果您禁用历史文件,您仍然可以在 shell 运行时访问运行时历史。您还可以设置HISTFILESIZE控制保存在文件中的命令数量。
使用HISTCONTROL和/或防止在历史记录中保存某些命令HISTIGNORE。设置HISTCONTROL为ignorespace将告诉 shell 不保存以空格开头的命令行。HISTIGNORE可以包含不保存在历史记录中的命令模式。例如,HISTIGNORE='ls:ls *'将阻止保存仅包含ls或ls,一个空格以及之后的任何内容的行。
对于“健忘症”外壳,您需要在打开外壳时手动应用这些设置之一,或者在某些外壳启动脚本中进行设置。
一种选择是创建,例如~/.bashrc.nohist:
# include the standard startup files as --rcfile will override them
if [ -f /etc/bash.bashrc ] ; then
. /etc/bash.bashrc
fi
if [ -f ~/.bashrc ] ; then
. ~/.bashrc
fi
# disable history completely
HISTSIZE=0
# disable the history file
unset HISTFILE
# we could even set a reminder in the prompt
PS1="[nohist] $PS1"
Run Code Online (Sandbox Code Playgroud)
然后安排 shell 以bash --rcfile ~/.bashrc.nohist. 根据口味调整脚本。
| 归档时间: |
|
| 查看次数: |
1510 次 |
| 最近记录: |