How to log the time taken for a unix command? How to log the time taken for a unix command? unix unix

How to log the time taken for a unix command?


Use the time command (details):

time your_prog

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

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


The time command shows how long your process runs:

$ time sleep 2real    0m2.002suser    0m0.000ssys 0m0.000s$  

sleep 2 is just a simple process that takes 2 seconds.

To log the current time, use the date command.


I am not sure I get your question. time <command> will give the time taken by <command>. If you want the actual start and end times to be printed as well, you can do:

echo "start time = $(date)"time <command>echo "end time = $(date)"