Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get just real time value from 'time' command?

I would like to make a script that outputs only the real time value from the time command so I can plot the results. For example time command outputs

real    1m0.001s user    1m0.000s sys  0m0.001s 

I want to write a script that outputs

60.001  

How do I get just real time value from 'time' command in seconds?

like image 610
Matthew Sowders Avatar asked Sep 25 '10 20:09

Matthew Sowders


People also ask

How do you use time command?

Time Command Versions To use the Gnu time command, you need to specify the full path to the time binary, usually /usr/bin/time , use the env command or use a leading backslash \time which prevents both and built-ins from being used.

What is time command output?

This is all elapsed time including time slices used by other processes and time the process spends blocked (for example if it is waiting for I/O to complete). User is the amount of CPU time spent in user-mode code (outside the kernel) within the process. This is only actual CPU time used in executing the process.

How do you use the time command on a Mac?

Current time in Mac OSX for command above is: /usr/bin/time: illegal option -- f usage: time [-lp] command.

How do I get the current time in Linux terminal?

To use the timedatectl command, type “timedatectl” at the command prompt. This will display the current system time and date settings.


2 Answers

If you're using the Bash builtin time, set the TIMEFORMAT variable to %R:

$ TIMEFORMAT=%R $ time sleep 1 1.022 
like image 84
Dennis Williamson Avatar answered Sep 23 '22 12:09

Dennis Williamson


time can take an optional --format or -f parameter, but you have to use the full path to the time command, /usr/bin/time

/usr/bin/time -f "%e" sleep 3  3.00 

Without the path, it'll use the time command of the shell which just treats all arguments as the command, so you'll get an -f: command not found.

like image 30
eumiro Avatar answered Sep 24 '22 12:09

eumiro