/ factorpad.com / tech / linux-essentials / time-command.html
An ad-free and cookie-free website.
Intermediate
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
System.
time
allows you to show command
execution time.
-options | description |
---|---|
-p |
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)
.
The 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
built-ins.
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 time
command. Many Linux distributions have a different
time
program. To see what you have
use a type -a
from video #11,
like so.
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
funscript
.
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
y
.
Next, let's time this script, using
time funscript
.
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 time
.
And you know the syntax for commands, options and arguments.
One last tip about the time
command. So for added functionality, try installing and aliasing a
more full-featured time
command on
your end if you'd like.
Okay, thanks for visiting today. I hope this was a helpful
introduction to the time
command.
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.
source
command,
hit Back.read
, click Next./ factorpad.com / tech / linux-essentials / time-command.html
A newly-updated free resource. Connect and refer a friend today.