如何记录unix命令所需的时间? [英] How to log the time taken for a unix command?

查看:167
本文介绍了如何记录unix命令所需的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我的脚本将需要超过10小时才能运行。有没有办法记录它的开始时间和结束的时间?

I know my script is going to take more than 10 hours to run. Is there a way to log the time it starts and the time it ends ?

时间命令只是时间过程还是我得到我计时的过程的输出?

Does the time command just time the process or do I get the output of the process that I'm timing ?

推荐答案

使用 time 命令(详情):

time your_prog

如果时间不适合你,我会尝试记录 date 详细信息)在程序执行之前和之后,例如

If time does not fit for you, I would try to log the output of date (details) before and after the execution of your program, e.g.

date > log.txt; your_prog; date >> log.txt

最后,您还可以添加一些格式(注意:灵感来自Raze2dust的回答):

Finally, you can also add some formatting (NOTE: inspired by Raze2dust's answer):

echo "started at: $(date)" > log.txt; your_prog; echo "ended at: $(date)" >> log.txt

这篇关于如何记录unix命令所需的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆