记录命令执行时间
有一种可爱的方法可以在 Linux 控制台中记录所有命令的开始日期/时间。您应该将变量 HISTTIMEFORMAT 设置为“%F %T ”。然后通过运行“history”命令,您将看到类似以下内容:
512 2011-09-02 22:57:41 export HISTTIMEFORMAT="%F %T " 513 2011-09-02 22:57:42 ls 514 2011-09-02 22:57:43 hist 515 2011-09-02 22:57:45 history
这非常酷且有用。但我的梦想是将命令执行时间也添加到此日志中。我知道我可以运行“time ./some_long_last_script”,但我不想每次都手动写入时间。也许有某种方法可以自动保存每个命令的执行时间?
There is a cute way of loggin the start date/time of all commands in linux console. You should set the variable HISTTIMEFORMAT to "%F %T ". Then by running 'history' command you will see something like:
512 2011-09-02 22:57:41 export HISTTIMEFORMAT="%F %T " 513 2011-09-02 22:57:42 ls 514 2011-09-02 22:57:43 hist 515 2011-09-02 22:57:45 history
This is very cool and useful. But my dream is to add to this log also the command execution time. I know that I can run 'time ./some_long_lasting_script' but I don't want to write time every time manually. Maybe there is some way of auto saving every command execution time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不太分散注意力,您可以更改提示以显示当前日期和时间。
如果您使用的是 bash,请考虑类似:
看起来像:
当然,您可以根据您的个人喜好定制提示。
要永久更改提示,您可以将
export PS1=...
添加到~/.bashrc
文件中。或者,您可以编写别名来来回切换,例如,在您的~/.bashrc
文件中,请注意
...
应该是您选择的双引号附带的提示字符串。关于 PS1 转义序列的一些参考:此处 和此处
If it wasn't too distracting, you could change your prompt to display the current date and time.
If you're using bash, consider something like:
which would look like:
You could, of course, tailor your prompt to your personal preferences.
To permanently change your prompt you can add that
export PS1=...
to your~/.bashrc
file. Alternatively, you could write aliases to toggle back and forth, for example, in your~/.bashrc
file,Note that
...
should be your choice of double-quote enclosed prompt string.Some references on PS1 escape sequences: here and here