我想检查我的 linux 系统,当哪个命令被解雇-在哪个日期和时间。
我发射命令是这样的:
history 50
它向我展示了最后 50 个命令的历史记录,但没有显示它被触发的日期和时间。
Regarding this link您可以通过执行以下命令使first solution provided by krzyk成为永久性的:
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
source ~/.bash_profile
试试这个:
> HISTTIMEFORMAT="%d/%m/%y %T "
> history
当然,您可以根据自己的喜好调整格式。
如果您使用的是 zsh,则可以使用-E
或-i
开关:
history -E
如果您执行man zshoptions
或man zshbuiltins
,您可以找到有关这些开关的更多信息以及与历史记录相关的其他信息:
Also when listing,
-d prints timestamps for each event
-f prints full time-date stamps in the US `MM/DD/YY hh:mm' format
-E prints full time-date stamps in the European `dd.mm.yyyy hh:mm' format
-i prints full time-date stamps in ISO8601 `yyyy-mm-dd hh:mm' format
-t fmt prints time and date stamps in the given format; fmt is formatted with the strftime function with the zsh extensions described for the %D{string} prompt format in the section EXPANSION OF PROMPT SEQUENCES in zshmisc(1). The resulting formatted string must be no more than 256 characters or will not be printed
-D prints elapsed times; may be combined with one of the options above
它取决于标准 bash 中的 shell(及其配置),只有命令存储没有日期和时间(检查.bash_history
如果有任何时间戳)。
要让 bash 存储时间戳,您需要在HISTTIMEFORMAT
之前执行命令,例如在.bashrc
或.bash_profile
中。这将导致 bash 将时间戳存储在.bash_history
中(请参阅以#
开头的条目)。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(61条)