Linux 检索命令行历史记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8561983/
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-08-06 03:43:34  来源:igfitidea点击:

Retrieving command line history

linuxbashubuntu-11.04

提问by Greenhorn

I use ubuntu 11.04, and the question must be common to any bash shell. Pressing the up arrow key on your terminal will retrieve the previous command you had executed at your terminal.

我使用 ubuntu 11.04,这个问题对于任何 bash shell 来说都必须是共同的。按终端上的向上箭头键将检索您在终端上执行的上一个命令。

My question is where(in which file) will all these command history be stored? Can I read that file?

我的问题是所有这些命令历史记录将存储在哪里(在哪个文件中)?我可以读那个文件吗?

采纳答案by Kent

the history filename was stored in variable : $HISTFILE

历史文件名存储在变量中:$HISTFILE

echo  $HISTFILE 

will give you the right file.

会给你正确的文件。

Usuallyin bash it would be ~/.bash_history, however it could be changed by configuration.

通常在 bash 中它会是 ~/.bash_history,但是它可以通过配置进行更改。

also notice that sometimes the very last commands is not stored in that file. running

还请注意,有时最后的命令未存储在该文件中。跑步

history -a

will persistent.

会执着。

history -r 

will clean those command not yet written to the file.

将清除那些尚未写入文件的命令。

回答by Chewie

For bash, it is by default in ~/.bash_history(check the HISTFILEenvironment variable if it isn't). You can directly catthe file or use the historycommand.

对于 bash,它默认在~/.bash_historyHISTFILE如果不是,请检查环境变量)。您可以直接cat文件或使用history命令。