August 4th, 2009 Add Your Comments

What to find out how long command will take to run? Perhaps you need to know how long your capistrano deployment is taking to run.

Just type ‘time’ in front of your command and you’re done:

$ time ps aux
...
root        14   0.0  0.1    77000   1896   ??  Ss   23Jul09  43:36.24 /usr/sbin/configd
root        13   0.0  0.0   601332    632   ??  Ss   23Jul09   4:02.60 /usr/sbin/syslogd
root        12   0.0  0.0   600236    440   ??  Ss   23Jul09   5:40.11 /usr/sbin/notifyd
root        11   0.0  0.1    78872   3460   ??  Ss   23Jul09   8:05.65 /usr/sbin/DirectoryService
root        10   0.0  0.0    75968    992   ??  Ss   23Jul09   0:01.82 /usr/libexec/kextd
root         1   0.0  0.0   600820    536   ??  Ss   23Jul09   3:22.52 /sbin/launchd
...
ps aux  0.01s user 0.04s system 6% cpu 0.694 total

That’s all there is to it.

From the man pages:

NAME
time -- time command execution

SYNOPSIS
time [-lp] utility

DESCRIPTION
 The time utility executes and times utility.  After the utility finishes,
 time writes the total time elapsed, the time consumed by system overhead,
 and the time used to execute utility to the standard error stream.
 Times are reported in seconds.