Home > Mobile >  How to get start and end date of a command with the 'time' command in linux?
How to get start and end date of a command with the 'time' command in linux?

Time:06-21

I'm doing some data transfers and using the 'time' command to measure how long it takes for the transfer to complete. The command is time bbcp source destination Unfortunately it doesn't show the start and end date, only the number of seconds the command took to run. Is there any way to do this without complicated scripts?

CodePudding user response:

Simplest would be to call date, before and after, like:

date; bbcp source destination; date

if you want a date format that is parsable you can do

date  %s; bbcp source destination; date  %s

CodePudding user response:

Please don't kill me for such a simple answer, but if I want to do something like this, I use this command for knowing the current time (accuracy in milliseconds date "%T.%3N"), as follows:

Prompt> date  "%T.%3N"
Prompt> Launch_Whatever
Prompt> date  "%T.%3N"

This shows me two dates, which I can subtract from each other in order to know the duration. If your Launch_Whatever generates a lot of output, you might always capture the timestamps in a temporary file:

Prompt> date  "%T.%3N" >/tmp/datetime.txt
Prompt> Launch_Whatever
Prompt> date  "%T.%3N" >>/tmp/datetime.txt

The first one creates the datetime.txt file, the second one adds the next entry.

  • Related