-1

If you measure times in Ubuntu 18.04, the result apears in a single line:

$ time sleep 1
sleep 1  0.00s user 0.00s system 0% cpu 1.003 total

This doesn’t align with the POSIX standard, as described in time’s man page:

-p, --portability
       Use the following format string, for conformance with POSIX standard 1003.2:
                 real %e
                 user %U
                 sys %S

Now my question is:

Why does Ubuntu use its own format for displaying resource usage?

Also, how do I change the behavior? Using the -p option from the manual I cited above, I only get the following error:

$ time -p sleep 1           
zsh: command not found: -p
-p sleep 1  0.00s user 0.00s system 73% cpu 0.002 total
pvorb
  • 101

1 Answers1

6

Your error is a huge clue -

zsh: command not found: -p

You are using zsh not BASH or DASH.

The man page for time pertains to the external /usr/bin/time program: bash as well as zsh provides its own time shell builtin (which happens to have an equivalent -p switch)

correcting comment by @steeldriver

I get a different result on my standard Ubuntu using the default bash - or what you no doubt want/expect.

guiverc@d960-ubu2:~$  time -p sleep 1
real 1.09
user 0.00
sys 0.00
guiverc
  • 30,396
  • 6
    The man page for time pertains to the external /usr/bin/time program: bash as well as zsh provides its own time shell builtin (which happens to have an equivalent -p switch), but it's not really correct to say that the man pages are "for bash/dash/sh" – steeldriver Dec 23 '18 at 02:25
  • 1
    … so the answer is: To use the external time rather than any shell builtin, call it with its full path /usr/bin/time -p sleep 1! – dessert Dec 23 '18 at 21:01
  • zsh, right! I could've realized that on my own, but thank you for clarifying this. – pvorb Dec 24 '18 at 12:13