GSh*_*aik 5 shell command-history utilities
在 Linux 中,一般我们会使用很多命令,并且很难记住所有这些命令。
history
Run Code Online (Sandbox Code Playgroud)
command 提供了我们之前使用的命令列表,但它的限制较少。新命令被旧命令覆盖,然后旧命令丢失。我认为命令日志存储在系统中的某个地方。
该日志是否可以打开和阅读?如果可能,我们可以更改它可以处理的最大日志大小吗?
history命令的输出是否取决于登录用户?
ter*_*don 14
一个简单的解决方案是增加由history. 如果您使用 bash,请将这一行添加到您的~/.profile:
export HISTSIZE=100000
export HISTFILESIZE=999999
Run Code Online (Sandbox Code Playgroud)
来自man bash:
HISTFILESIZE
The maximum number of lines contained in the history file. When
this variable is assigned a value, the history file is trun?
cated, if necessary, to contain no more than that number of
lines by removing the oldest entries. The history file is also
truncated to this size after writing it when a shell exits. If
the value is 0, the history file is truncated to zero size.
Non-numeric values and numeric values less than zero inhibit
truncation. The shell sets the default value to the value of
HISTSIZE after reading any startup files.
HISTSIZE
The number of commands to remember in the command history (see
HISTORY below). If the value is 0, commands are not saved in
the history list. Numeric values less than zero result in every
command being saved on the history list (there is no limit).
The shell sets the default value to 500 after reading any
startup files.
Run Code Online (Sandbox Code Playgroud)
该文件~/.bash_history保存了已执行命令的列表。至少CentOS有这个文件,不知道其他发行版有没有。
没有这样的日志,至少默认情况下没有。
您可以安装一些工具,例如acct(“用于进程和登录记帐的 GNU 记帐实用程序”),它们可以跟踪系统上执行的所有程序。
acct为大多数(可能除了tiny-distros 之外的所有)linux 发行版打包。主页位于http://www.gnu.org/software/acct/
acct提供以下命令,lastcomm可能满足您的要求:
ac 打印有关用户连接时间的统计信息。ac 可以告诉您特定用户或用户组连接到您的系统的时间,按天打印总计或 wtmp 文件中的所有条目。
accton 打开或关闭会计。
lastcomm 列出系统上执行的命令,最近的在前,显示每个命令的运行状态。最后,您可以搜索特定用户、终端或命令的 acct 文件。
sa 将acct 文件中的信息汇总到savacct 和usracct 文件中。它还生成有关命令的报告,提供调用次数、使用的 CPU 时间、平均核心使用率等。
dump-acct dump-utmp 以人类可读的格式显示 acct 和 utmp 文件。