无法清除 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:51:00  来源:igfitidea点击:

Unable to clear Bash terminal history in OS X El Capitan

macosbashterminalosx-elcapitan

提问by Psychomentality

After upgrading to OS X El Capitan (at least I noticed after update), in bash, history -ccommand 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_historyfile but actually I am curious about this new behaviour?

我知道可能会删除.bash_history文件,但实际上我对这种新行为感到好奇?

Maybe it is related to new .bash_sessionsfeature. Is there any way to use history -cas 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 -wclears 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

I used:

我用了:

cat /dev/null > ~/.bash_history && history -c

I used thistopic, maybe you could find more info there?

我用过这个话题,也许你可以在那里找到更多信息?

回答by avivamg

In short:your bash History in the terminal is located in ~/.bash_historyor 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 或记事本打开它并保存更改。