Linux 带日期和时间的命令历史记录
Linux Command History with date and time
我想查看我的 linux 系统何时触发了哪个命令 - 在哪个日期和时间。
我发射了这样的命令:
history 50
它向我显示了最近 50 个命令的历史记录,但没有显示它被触发的日期和时间。有人知道怎么做吗?
试试这个:
> HISTTIMEFORMAT="%d/%m/%y %T "
> history
当然,您可以根据自己的喜好调整格式。
这取决于标准 bash 中的 shell(及其配置)仅存储命令而没有日期和时间(检查 .bash_history
是否有任何时间戳) .
要让 bash 存储时间戳,您需要在 HISTTIMEFORMAT
执行命令之前设置 ,例如在 .bashrc
或 .bash_profile
中。这将导致 bash 将时间戳存储在 .bash_history
中(请参阅以 #
开头的条目)。
Regarding this link you can make the 永久执行:
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
source ~/.bash_profile
HISTTIMEFORMAT="%d/%m/%y %H:%M "
对于在此之前键入的任何命令,这将无济于事,因为它们只会获得您打开历史记录的默认时间,但它会记录此后任何其他命令的时间。
如果你想让它永久记录历史,你应该把下面的
在你的 ~/.bashrc
行
export HISTTIMEFORMAT="%d/%m/%y %H:%M "
如果您使用的是 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
我想查看我的 linux 系统何时触发了哪个命令 - 在哪个日期和时间。
我发射了这样的命令:
history 50
它向我显示了最近 50 个命令的历史记录,但没有显示它被触发的日期和时间。有人知道怎么做吗?
试试这个:
> HISTTIMEFORMAT="%d/%m/%y %T "
> history
当然,您可以根据自己的喜好调整格式。
这取决于标准 bash 中的 shell(及其配置)仅存储命令而没有日期和时间(检查 .bash_history
是否有任何时间戳) .
要让 bash 存储时间戳,您需要在 HISTTIMEFORMAT
执行命令之前设置 ,例如在 .bashrc
或 .bash_profile
中。这将导致 bash 将时间戳存储在 .bash_history
中(请参阅以 #
开头的条目)。
Regarding this link you can make the
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
source ~/.bash_profile
HISTTIMEFORMAT="%d/%m/%y %H:%M "
对于在此之前键入的任何命令,这将无济于事,因为它们只会获得您打开历史记录的默认时间,但它会记录此后任何其他命令的时间。
如果你想让它永久记录历史,你应该把下面的
在你的 ~/.bashrc
export HISTTIMEFORMAT="%d/%m/%y %H:%M "
如果您使用的是 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