Linux 自机器创建以来如何查找shell命令的历史记录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11372732/
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
How to find history of shell commands since machine was created?
提问by Edward Tanguay
I created an Ubuntu virtualbox machine a couple weeks ago and have been working on projects off and on in it since then.
几周前我创建了一个 Ubuntu 虚拟机,从那时起就一直在做项目。
Now I would like to find the syntax of some commands I typed in the terminal a week ago, but I have opened and closed the terminal window and restarted the machine numerous times.
现在我想找到我一周前在终端中输入的一些命令的语法,但我已经打开和关闭了终端窗口并重新启动了无数次机器。
How can I get the history
command to go back to the first command I typed after I created the machine, or is there another place that all the commands are stored in Ubuntu?
如何让history
命令返回到我创建机器后输入的第一个命令,或者是否有其他地方将所有命令存储在 Ubuntu 中?
回答by paulsm4
1) The size of the history file is governed by the environment variable HISTSIZE. The default is 500 lines on most systems.
1) 历史文件的大小由环境变量 HISTSIZE 控制。大多数系统上的默认值是 500 行。
2) You can set $HISTSIZE in your ~/.bashrc (or other) initialization file.
2)您可以在您的 ~/.bashrc(或其他)初始化文件中设置 $HISTSIZE。
3) You can check your current history simply by typing "history".
3) 您只需输入“历史”即可查看您当前的历史记录。
4) You can learn more about the command and various options by typing "man history".
4) 您可以通过键入“man history”了解有关命令和各种选项的更多信息。
Here's a good article on the subject:
这是一篇关于这个主题的好文章:
回答by tripleee
In the general case, there is no facility that permanently records all commands in all shells. Bash has a limited history, but once your commands rolled off the history list, they're gone. If your command involved sudo
, the system logs may contain all or parts of the command lines you would like to retrieve. The virtual machine you are using may offer a facility for going backwards in time.
在一般情况下,没有工具可以永久记录所有 shell 中的所有命令。Bash 的历史是有限的,但是一旦您的命令从历史列表中滚出,它们就消失了。如果涉及您的命令sudo
,系统日志可能包含您要检索的全部或部分命令行。您正在使用的虚拟机可能会提供一种让时间倒退的工具。