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.
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!
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.
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
@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.
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
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 🙂
Just what I was looking for, thanks! Hit #3 when I googled ubuntu time command
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?