let rec weng = ~weng cv misc contact blog 博客


What is `time`

2020-05-19

time is a common shell utility to measure the elapsed time. I occasionally found someone use /usr/bin/time instead of time and sometimes /usr/bin/time doesn’t exist. I search for this topic a bit and think it’s subtler that I initially expected.

$ type -a time
type -a time
time is a shell keyword
time is /usr/bin/time

$ time --version
time --version
bash: --version: command not found

$ time --version
zsh: command not found: --version
--version  0.00s user 0.00s system 0% cpu 0.019 total

$ /usr/bin/time --version
GNU time 1.7

I run this on my ubuntu in wsl and a server running debian. However, for a fresh image, GNU time may be not installed yet.

$ type -a time
time is a shell keyword

$ /usr/bin/time
-bash: /usr/bin/time: No such file or directory

Therefore, the quick answer to the question in the title is

  1. time is a shell command
  2. time at /usr/bin/time is GNU time

It’s better we just use one of them in one shell script. This answer says bash time is more precise than GNU time since getusage() has better microsecond resolution than times() in each code.

p.s.1 Technically, bash time is a command/keyword but not a builtin, though people tend to call it a shell builtin.

$ builtin time
builtin time
bash: builtin: time: not a shell builtin
$ builtin cd
builtin cd

p.s.2 bash is indeed GNU bash.


What is `time`