Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Why does running time and /usr/bin/time give different results?

/usr/bin/time

thomas@tbdesktop:~$ /usr/bin/time -f "Elapsed time:%E" wc /etc/hosts
  9  25 224 /etc/hosts
Elapsed time:0:00.04

time

thomas@tbdesktop:~$ time -f "Elapsed time:%E" wc /etc/hosts
-f: command not found

real    0m0.079s
user    0m0.052s
sys 0m0.024s

My path is as follows. As far as I can see, there is only one time executable in the path.

thomas@tbdesktop:~$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
thomas@tbdesktop:~$ find / -name time 2> /dev/null
/sys/devices/pnp0/00:03/rtc/rtc0/time
/sys/module/printk/parameters/time
/var/lib/dkms/virtualbox/4.1.12/build/common/time
/var/lib/doc-base/documents/time
/usr/src/linux-headers-3.2.0-30/kernel/time
/usr/src/linux-headers-3.2.0-31-generic/include/config/sr/report/time
/usr/src/linux-headers-3.2.0-31-generic/include/config/generic/time
/usr/src/linux-headers-3.2.0-31-generic/kernel/time
/usr/src/virtualbox-4.1.12/common/time
/usr/src/linux-headers-3.2.0-29/kernel/time
/usr/src/linux-headers-3.2.0-30-generic/include/config/sr/report/time
/usr/src/linux-headers-3.2.0-30-generic/include/config/generic/time
/usr/src/linux-headers-3.2.0-30-generic/kernel/time
/usr/src/linux-headers-3.2.0-29-generic/include/config/sr/report/time
/usr/src/linux-headers-3.2.0-29-generic/include/config/generic/time
/usr/src/linux-headers-3.2.0-29-generic/kernel/time
/usr/src/linux-headers-3.2.0-31/kernel/time
/usr/bin/time
/usr/share/doc/time
/usr/share/doc-base/time
thomas@tbdesktop:~$ 
share|improve this question

1 Answer 1

up vote 3 down vote accepted

Because time and /usr/bin/time run different code. In order to determine it, do the following:

type time

It will show you that:

time is a shell keyword

Thus, it doesn't run /usr/bin/time if you simply call time.

They are different things...

share|improve this answer
    
Great answer - thanks :) –  Thomas Bratt Oct 2 '12 at 14:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.