Time – Run Programs and Summarize System Resource Usage

By | 2007/09/23

Today’s post is a quickie, and more along the lines of a “package of the day”, but I thought it would be interesting to share.

The time command in Linux will offer you system resource summaries and total time taken to complete the job requested. Usage of the time command is very simple (although see man time for more information).

I used this command last to see how long it took to write psuedo-random data to a 6G USB disk:

time dd if=/dev/urandom of=/dev/sdb bs=4096

(example output, not accurate for this command)
real 22m1.513s
user 0m0.076s
sys 0m0.016s

The time command can be a prefix to just about any command you run and want a timed output for.  Give it a try.

8 thoughts on “Time – Run Programs and Summarize System Resource Usage

  1. mlissner

    You have no idea how long this command took me to find about two weeks ago when I needed it. I almost wrote a script to use date, bc and awk to accomplish the same task.

    Some of these really basic commands are nearly impossible to find (ie, you can’t google the word time and hope to get anything useful).

    Thanks!

  2. Adrian Bunk

    The “time command is a nice tool, but there are problems with your example, more exactly with what you are measuring. It is not exactly correct this would show “how long it took to write psuedo-random data to a 6G USB disk”:

    – Depending on how the disk is mounted, part of the data might not yet have been written to the disk but only cached in RAM when the end time gets measured.

    – /dev/urandom is slower than typical USB disks so you actually measure the speed of /dev/urandom, not the speed of the disk.

  3. Dirk Eddelbuettel

    You failed to point out the difference between ‘time’ (usually the bash builtin) and /usr/bin/time (aka the GNU time binary). As a long-time Debian maintainer for GNU time (but alas no longer the current maintainer) I can assure you that half the bug reports fell into that trap.

    Cheers, Dirk

  4. the polarizer

    @mlissner: For basic commands in linux try a “man bash” and search for “SHELL BUILTIN COMMANDS”. Another good idea is to use “apropos time” if you need such things on the console.

  5. MadMike

    You should really mention that your example will overwrite and erase all data on /dev/sdb. Else, some unsuspecting reader loose valuable data.

    Also: psuedo-random -> pseudo-random

  6. devnull

    I agree MadMike. Was just about to post the same thing. I hope noone ‘gives it a try’ before understanding what will happen to /dev/sdb 🙂

  7. a

    Just what I was looking for, thanks! Hit #3 when I googled ubuntu time command

  8. wlevels

    Tried time command to get it to work with a tar command, won’t work 🙁 tells me “time: cannot run tar. Command exited with non-zero status 127

    Anybody got an idea?

Comments are closed.