How can I output the real time a command takes (and nothing else)?
Example:
This won't work:
$ time -p sleep 2 | grep real
real 2.00
user 0.00
sys 0.00
I want something like:
$ print-real-time sleep 2
2.00
How can I output the real time a command takes (and nothing else)?
Example:
This won't work:
$ time -p sleep 2 | grep real
real 2.00
user 0.00
sys 0.00
I want something like:
$ print-real-time sleep 2
2.00
You need to capture the output of
time
first. Then you can process it.A non-BASH-specific solution (explicitly use
/usr/bin/time
so it's not the pipe-gobbling bash builtin) --/usr/bin/time -p some_command_or_subshell 2>&1 | grep real | awk '{print $2}'
Depending on the delicate nature of whatever you feed this output to you may want to redirect the output of your subject command to /dev/null...
Here's a hacky solution using
cut
to split the fields.You can also use
awk
: