Format of time <command> in bash:

$time ./test.sh

real    0m0.000s
user    0m0.006s
sys     0m0.000s

In zsh:

 $time ./test.sh                                                       
 ./test.sh  0.01s user 0.00s system 94% cpu 0.007 total

This always bothered me when I switched to zsh. How to make the output of time in zsh be like bash?

  • As a long-time zsh user, it always bothers me when I have to use bash and it's not able to give broken down times on pipelines and not telling you what the timing refers to. The one line output is also natural for anyone who used tcsh before (where the extended resource usage attributes comes from) Jan 17, 2020 at 16:30

1 Answer 1


The time keyword in zsh produces output in the format specified by the variable TIMEFMT.

The default value of this variable is

%J  %U user %S system %P cpu %*E total

You can change this like this, for example:

TIMEFMT=$'%J\n%U user\n%S system\n%P cpu\n%*E total'

(this really just inserts a few newline characters into the default format string)

Which gives the following kind of output:

$ time sleep 2
sleep 2
0.00s user
0.00s system
0% cpu
2.010 total

Or, somewhat closer to what bash has:

$ TIMEFMT=$'real\t%E\nuser\t%U\nsys\t%S'
$ time sleep 2
real    2.02s
user    0.00s
sys     0.01s

See the documentation for the TIMEFMT variable in the zshparam manual.

On my system (running zsh 5.7.1), this reads

          The format of process time reports with the time keyword.  The
          default is `%J  %U user %S system %P cpu %*E total'.  Recognizes
          the following escape sequences, although not all may be
          available on all systems, and some that are available may not be

          %%     A `%'.
          %U     CPU seconds spent in user mode.
          %S     CPU seconds spent in kernel mode.
          %E     Elapsed time in seconds.
          %P     The CPU percentage, computed as 100*(%U+%S)/%E.
          %W     Number of times the process was swapped.
          %X     The average amount in (shared) text space used in
          %D     The average amount in (unshared) data/stack space used in
          %K     The total space used (%X+%D) in kilobytes.
          %M     The  maximum memory the process had in use at any time in
          %F     The number of major page faults (page needed to be
                 brought from disk).
          %R     The number of minor page faults.
          %I     The number of input operations.
          %O     The number of output operations.
          %r     The number of socket messages received.
          %s     The number of socket messages sent.
          %k     The number of signals received.
          %w     Number of voluntary context switches (waits).
          %c     Number of involuntary context switches.
          %J     The name of this job.

          A star may be inserted between the percent sign and flags
          printing time (e.g., `%*E'); this causes the time to be printed
          in `hh:mm:ss.ttt' format (hours and minutes are only printed if
          they are not zero).  Alternatively, `m' or `u' may be used
          (e.g., `%mE') to produce time output in milliseconds or
          microseconds, respectively.

  • 1
    Note that zsh can not time builtins time for a do echo $a; done doesn't work in zsh.
    – user232326
    Jan 22, 2020 at 5:07
  • 1
    @ImHere it can if you put parentheses around everything after time
    – Eevee
    Aug 21, 2021 at 10:36
  • @Eevee Parentheses start a subshell, which migh (or not) important. Try: zsh -c 'echo "plain" $ZSH_SUBSHELL; time (echo "timed" $ZSH_SUBSHELL);'
    – user232326
    Aug 23, 2021 at 21:50

You must log in to answer this question.