bash 如何获取终端历史记录中每个命令行的时间戳?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14493145/
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 can I get the timestamp of each command line in my terminal history?
提问by abw333
I would like to know how long a command that I entered into my terminal has been running. It would be great to be able to get the timestamp of every command in my history. Let me know if you need any more information in order to be able to answer this question. Thanks.
我想知道我在终端中输入的命令已经运行了多长时间。能够获得我历史记录中每个命令的时间戳会很棒。如果您需要更多信息才能回答这个问题,请告诉我。谢谢。
EDIT: I am using a bash terminal.
编辑:我正在使用 bash 终端。
回答by Hitman47
Assuming you are using command prompt
假设您正在使用命令提示符
HISTTIMEFORMAT="%d/%m/%y %T "
then
然后
history
http://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/
http://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/
回答by user1034978
I don't think I know how to show the duration, but you can view the time you ran the command by setting the HISTTIMEFORMAT variable.
我想我不知道如何显示持续时间,但是您可以通过设置 HISTTIMEFORMAT 变量来查看运行命令的时间。
export HISTTIMEFORMAT='%F %T '
Then call your "history"
然后调用你的“历史”
history
If you only want to see last 10 commands
如果您只想查看最后 10 个命令
history | tail
Hope this help :)
希望这有帮助:)

