/ factorpad.com / tech / linux-essentials / which-command.html
An ad-free and cookie-free website.
Beginner
Learn to find command locations at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux which Command Summary with Examples (3:36)
Our eighteenth word, or command to memorize is which
from the category
Help.
which
allows you to locate commands.
-options | description |
---|---|
-a |
Print all matches |
Recall from the last video (tutorial) how we saw two versions of the
file
command in the Linux filesystem?
Well, I wanted to use the which
command to kick off a discussion about how Linux goes about finding
files.
Before we start, it helps to think about commands as mini programs and
most follow this structure:
command -option(s) argument(s)
.
The which
command has
1 option and the argument is the command you'd like
to find.
Unlike many other commands, which
does
not have a double-dash
--help
option.
So which
simply returns the location
of the argument, assuming it's an
executable, searching the what's called the PATH. And
the PATH is a list of directories Linux will search
when you enter a command. One caveat, on many distributions,
which
ignores the 60 or so shell
builtins.
So why is which
an important command?
Well, which
offers a quick answer if
you are searching for command locations.
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, let's type man which
, for
two reasons, first because we don't have a double-dash-help option and
second I wanted a throwback to those corny Manwhich commercials from
the 1980s. ;)
Next, let's use multiple arguments, one for the shell builtin command
type
, and another executable like
man
.
Notice how the builtin type
is ignored?
An inconvenience you are now aware of.
Okay now you know how to use which
.
And you know the syntax for commands, options and arguments.
One last tip about the which
command.
Yes, which
has limited value, but
offers an opening to the PATH variable, coming up next.
Okay, thanks for visiting today. I hope this was a fun introduction
to the which
command.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
The best way to leave feedback and ask questions is on YouTube. Subscribe there and follow @factorpad on Twitter for new content reminders.
file
command,
hit Back.echo
command, click
Next./ factorpad.com / tech / linux-essentials / which-command.html
A newly-updated free resource. Connect and refer a friend today.