PDA

View Full Version : How grep real time in bash?



Pithikos
November 6th, 2011, 03:27 PM
I want to only get the real time it takes for a command to run and save that to a variable in bash. However I can't make sense of what is happening.

I run

$(time ls &> /dev/null) | grep real > testbut file test remains empty while time is still written on screen. :confused:

MadCow108
November 6th, 2011, 03:36 PM
the output of the builtin time goes to stderr + it needs to go into a subshell:

(time ls) 2>&1 | grep real

learnbash
November 6th, 2011, 03:36 PM
Brother check below code.




# (time ls) 1> /dev/null 2> output
[root@server1 test]# cat output

real 0m0.003s
user 0m0.001s
sys 0m0.002s

Hope it helps


(time ls) 1> /dev/null
Above thing is ignorning output and sending it to /dev/null


2>output
Above thing is going to store error in output file, after that cat that file to see contents.

sanderd17
November 6th, 2011, 03:37 PM
EDIT: better explanations above