Results 1 to 2 of 2
Hi all,
I am new to Linux/shell scripting having moderate knowledge.
In my script, I need to get execution time of a command (say 'ls') in mili seconds level. For ...
- 01-21-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 4
Storing output of "time" command to a variable
Hi all,
I am new to Linux/shell scripting having moderate knowledge.
In my script, I need to get execution time of a command (say 'ls') in mili seconds level. For this i tried using "time" command to retrieve the total execution time in milli seconds. But, the problem is that, how to save the output of time command in a variable. The format of the command is like "time ls -R /opt"
Going further, the o/p of 'time' command is:
real 0m0.003s
user 0m0.004s
sys 0m0.000s
Here, in my script, I would like to use only middle line "user 0m0.004s" saved to the variable but unable to find out the way.
Can someone help me out with this issue. Thanks a lot.Last edited by linux_buzz; 01-21-2011 at 11:55 AM.
- 01-21-2011 #2Just Joined!
- Join Date
- Mar 2009
- Location
- Norway
- Posts
- 52
try
That way, the timing-stats will be written to the file time.stat. For further info about format, check out man timeCode:/usr/bin/time --output time.stat <command>


Reply With Quote