Change the output format of zsh's time
This is fairly close:
$ TIMEFMT=$'\nreal\t%E\nuser\t%U\nsys\t%S'
$ time sleep 1
real 1.01s
user 0.00s
sys 0.00s
Another option is to disable the builtin command and use the time binary provided by your operating system.
I have the following in my .zshrc
:
disable -r time # disable shell reserved word
alias time='time -p ' # -p for POSIX output
This way time outputs to STDERR.
Just a small precision regarding Dennis Williamson's very useful answer (the "fairly close" part): bash's built-in time
outputs to stderr
, while zsh's outputs to stdout
.
This command can illustrate the difference: time (echo abc) 2>/dev/null
In bash, it outputs:
$ time (echo abc) 2>/dev/null
abc
In zsh, with the suggested TIMEFMT variable:
$ time (echo abc) 2>/dev/null
abc
real 0.00s
user 0.00s
sys 0.00s