在 Linux 中禁用历史记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18663078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disable history in Linux
提问by ?mega
To disable a history in Linux environment I've executed the following commands:
要在 Linux 环境中禁用历史记录,我执行了以下命令:
export HISTFILESIZE=0
export HISTSIZE=0
unset HISTFILE
Is such command combination enough or I have to also execute history -cor something else?
这样的命令组合是否足够,或者我还必须执行history -c或其他什么?
Will this keep history disabled even when I reboot a server or such commands need to be executed after reboot again and again?
即使我重新启动服务器,这是否会禁用历史记录,或者在重新启动后需要一次又一次地执行此类命令?
采纳答案by konsolebox
Just add this command to a bash startup file which could be /etc/profile, ~/.bash_profile, ~/.bash_login, ~/.profile, or ~/.bashrcdepending your target scope and distro that customizes bash. See the INVOCATIONsection of bash's manual (man bash).
就在这个命令添加到它可能是一个bash的启动文件/etc/profile,~/.bash_profile,~/.bash_login,~/.profile,或~/.bashrc根据该定制的bash你的目标范围和发行。请参阅INVOCATIONbash 手册 ( man bash) 部分。
shopt -u -o history
Or
或者
set +o history
Which would disable history.
这将禁用历史记录。
Although you have to clear your history once:
尽管您必须清除一次历史记录:
history -c
And also delete your ~/.bash_historyfile.
并删除您的~/.bash_history文件。
回答by OneOfOne
If you want it to persist through reboots, you can add them to ~/.bashrcor /etc/profile.
如果您希望它在重新启动后持续存在,您可以将它们添加到~/.bashrc或/etc/profile。
回答by mata
For most usecases, unset HISTFILEshould be enough.
对于大多数用例,unset HISTFILE应该足够了。
That disables writing the history file, while it still allows to cycle through the last commands using up/down.
Changing HISTFILESIZEdoesn't have any effect when you unset HISTFILE, as it only affects how many lines will be written to the history file when the shell exits. If set to 0 with HISTFILEset, then the file will be truncated to 0 at exit.
Changing HISTSIZEchanges how many commands the current shell will remember.
这将禁用写入历史文件,同时它仍然允许使用up/循环执行最后一个命令down。当您 unset 时,
更改HISTFILESIZE没有任何影响HISTFILE,因为它只影响在 shell 退出时将有多少行写入历史文件。如果使用 set 设置为 0 HISTFILE,则文件将在退出时被截断为 0。
更改会HISTSIZE更改当前 shell 将记住的命令数量。
To make this changes permanent, ~/.bashrcor ~/.profileare good places to insert the commands.
使此更改永久化,~/.bashrc或者~/.profile是插入命令的好地方。

