Linux "time" command output redirection
Posted on 2016-11-06
I'm wanting concise way to get the "real" figure from the output of the "time" command.
Here's what I've tried:
$ time sleep 5
real 0m5.001s <= This is what I want to extract.
$ time sleep 5 | grep real
$ time sleep 5 2>&1 | grep real
$ time sleep 5 2>/dev/null | grep real
$ time sleep 5 1>/dev/null | grep real
$ time sleep 5 3>/dev/null | grep real
$ man time | grep -iC1 std
-o FILE, --output=FILE
Do not send the results to stderr, but overwrite the specified file.
So, it looks as if the output should be going to stderr by default, but as you can see above, it doesn't appear to be.
$ time -o myfile cal
-bash: -o: command not found # What the???
$ time --output=myfile sleep 5
-bash: --output=myfile: command not found
What is going on?
Note: I have removed/inserted some blank lines above for readability.
I think the OS is some kind of Cloud Linux and it's on a shared webhost.
$ uname -a
Linux server...etc... 3.10.0-427.10.1.lve1.4.22.el7.x86_64 #1 SMP Fri Oct 21 09:45:54 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux