Faster Learning Tutorials

Linux which command summary with examples

which allows you to locate commands.
  1. Purpose - Learn what which is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with which.
  4. A tip - Finish off with one more insight.
Paul Alan Davis, CFA, October 11, 2016
Updated: July 28, 2018
In this tutorial, 18 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Next

~/ home  / tech  / linux essentials  / which command

The Linux which command


Learn to find command locations at the Linux command line.

Video Tutorial

Linux which command summary with examples (3:36)

Videos can also be accessed from the YouTube Playlist.

Video Script

The Command and Why You Need It

Our eighteenth word, or command to memorize is which from the category Help.

which allows you to locate commands.

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. ;)

WHICH(1) General Commands Manual WHICH(1) NAME which - locate a command SYNOPSIS which [-a] filename ... DESCRIPTION which returns the pathnames of the files (or links) which would be executed in the current environment, had its arguments been given as commands in a strictly POSIX-conformant shell. It does this by searching the PATH for executable files matching the names of the arguments. It does not follow symbolic links. OPTIONS -a print all matching pathnames of each argument (remaining lines trimmed)

Next, let's use multiple arguments, one for the shell builtin command type, and another executable like man.

$ which type man /usr/bin/man

Notice how the builtin type is ignored? An inconvenience you are now aware of.

A Final Tip

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.

Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:

What's Next?

The best way to leave feedback and ask questions is on YouTube. Subscribe here.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the file command, hit Back.
  • To learn about printing text and variables to the screen with the frequently-used echo command, click Next.

Outline Back Next

~/ home  / technology  / linux essentials  / which command

Linux which command
locate commands
how to find commands in linux
linux command locations
multiple command locations
linux which command
linux which tutorial
unix which
which command options
linux which syntax
linux which command summary