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.

If this site has been useful, please consider participating in the Fundraiser.

Other Points of Interest

  • No Related Post

Comments

6 Responses to “Time - Run Programs and Summarize System Resource Usage”

  1. mlissner on September 23rd, 2007 10:53 am

    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 on September 23rd, 2007 12:07 pm

    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 on September 23rd, 2007 6:27 pm

    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 on September 25th, 2007 12:58 am

    @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 on September 25th, 2007 2:19 am

    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 on September 27th, 2007 3:50 am

    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 :)

Leave a Comment




    Subscribe to the RSS feed!


    subscribe to the ubuntu tutorials RSS feed

    Ubuntu Tutorials Fundraiser


    Please Donate to
    Server Improvement

    Target amount: USD1,000.00
    Total Donations: USD255.00
    Amount Needed: USD745.00

    Thank you for your support!

    Click to Donate

    Polls



  • Blogroll

  • Ads by Google