An ad-free and cookie-free website.
Learn to measure execution time at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux time Command Summary with Examples (3:38)
Our eighty-eighth word, or command to memorize is
time from our category
time allows you to show command
||Use output specified by POSIX|
Recall from our last video (tutorial) we started a script to tie together what we've learned, and now we'll measure the elapsed time it takes to run our newly created script using a shell built-in.
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s).
time command has
1 option and the argument is a command, and since
we're writing it, we're calling it a script.
Unlike most commands, help is not available with double-dash
--help, so here look in the
man page for
bash, as you would with other
So why is
time an important command?
Well, help it's helpful to measure our script run time.
And now you know how to do that.
Okay, the best way to embed this in your memory is by typing in your own terminal window.
Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.
Here we go. So to get ahead of any confusion, I'm referring to the
shell built-in here for the
command. Many Linux distributions have a different
time program. To see what you have
type -a from video #11,
You can see, mine is just the built-in.
Now, let's open the script from video (tutorial) #87, using video #20's
nano in the
~/bin/ directory and called
And add video #43's
sleep command so
the script takes 2 seconds.
Remember to add a comment, and feel free to pause the video to catch
up on your end if you'd like. Then close
Ctrl-x and save
Next, let's time this script, using
First is the time from start to finish, then the user CPU time and system CPU time.
And last, to clarify, we didn't have to
source the script like we did in the
last video (tutorial) #87 as our PATH now includes this
~/bin directory, so
bash can find it.
Okay now you know how to use
And you know the syntax for commands, options and arguments.
One last tip about the
command. So for added functionality, try installing and aliasing a
time command on
your end if you'd like.
Okay, thanks for visiting today. I hope this was a helpful
introduction to the
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
If you need a break from shell scripting, check out the other free stuff our YouTube Channel and ad-free website have to offer.
sourcecommand, hit Back.
read, click Next.
A newly-updated free resource. Connect and refer a friend today.