-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
  • 2
  • @guiverc Please post that as an answer, thanks! (To be clear, the comments section is not suitable for answers.) – wjandrea Dec 23 '18 at 02:02
  • 1
    Related: [Why doesn't the `time` command work with any option?](https://askubuntu.com/questions/434289/why-doesnt-the-time-command-work-with-any-option) – steeldriver Dec 23 '18 at 03:03
  • Why the downvote? What should I improve about this question? It wasn't obvious to me that `time`was a `zsh` built-in in my case that doesn't align with the man page of the installed standalone binary. – pvorb Dec 24 '18 at 12:17

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
  • 28,623
  • 5
  • 46
  • 74
  • 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