无法清除 OS X El Capitan 中的 Bash 终端历史记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33443463/
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
Unable to clear Bash terminal history in OS X El Capitan
提问by Psychomentality
After upgrading to OS X El Capitan (at least I noticed after update), in bash, history -c
command does not work as usual.
升级到 OS X El Capitan 后(至少我在更新后注意到),在 bash 中,history -c
命令无法正常工作。
History clearing only works for current tab. After opening another tab, it is possible to access history.
历史清除仅适用于当前选项卡。打开另一个选项卡后,可以访问历史记录。
I know it is possibly to remove .bash_history
file but actually I am curious about this new behaviour?
我知道可能会删除.bash_history
文件,但实际上我对这种新行为感到好奇?
Maybe it is related to new .bash_sessions
feature. Is there any way to use history -c
as usual (clearing history across every bash instances)?
也许它与新.bash_sessions
功能有关。有什么办法可以history -c
像往常一样使用(清除每个 bash 实例的历史记录)?
Thanks.
谢谢。
回答by Todd A. Jacobs
HISTFILE Isn't ~/.bash_history
HISTFILE 不是 ~/.bash_history
On OS X, the shell variable HISTFILEdoesn't seem to point to ~/.bash_history. Instead, it points to some sort of temp file like:
在 OS X 上,shell 变量HISTFILE似乎没有指向 ~/.bash_history。相反,它指向某种临时文件,例如:
/Users/$LOGNAME/.bash_sessions/7F058D96-4161-4F7C-B9F7-CFFEB43C35B2.historynew
/Users/$LOGNAME/.bash_sessions/7F058D96-4161-4F7C-B9F7-CFFEB43C35B2.historynew
As a result, history -c; history -w
clears the current history buffer, but doesn't actually clear the on-disk history file. It's unclear to me how/when the HISTFILEis written to ~/.bash_history, so you may need to clear the file manually. For example:
因此,history -c; history -w
清除当前历史缓冲区,但实际上并没有清除磁盘上的历史文件。我不清楚HISTFILE是如何/何时写入 ~/.bash_history 的,因此您可能需要手动清除该文件。例如:
history -c; history -w; rm ~/.bash_history
回答by OldBunny2800
回答by avivamg
In short:your bash History in the terminal is located in ~/.bash_history
or if you using oh-my-zsh in ~/.zsh_history
. Just open the file and delete the specific command line you wish for. I'm using vim but you can open it with any IDE or notepad and save the changes.
简而言之:你的bash历史在终端位于~/.bash_history
你使用哦,MY-的zsh或者~/.zsh_history
。只需打开文件并删除您想要的特定命令行。我正在使用 vim,但您可以使用任何 IDE 或记事本打开它并保存更改。