Linux / Unix: which Command Examples To Find Out A Program File

which command

I am a new Linux and Unix-like system user. How do I find out gcc compiler path on Linux? How can I locate a program file in path on Linux or Unix-like systems?

The which command shows the full path for each of its given arguments. This command searchers for an executable or script in the user’s PATH.[donotprint]

which command details
DescriptionLocate a program file
Root privilegesNo
Est. reading time5m
Table of contents
[/donotprint] I often use which command to find the executable file associated with a given command name.


Display the full path of shell commands.


The basic syntax is as follows:

which command


which [option] command


which prgoram

which command examples

To find the executable file associated with a command name of date:
$ which date

To find the executable file associated with a command name of httpd, top, and ls, type:
$ which httpd top ls

How can I list all instances of executables found?

Pass the -a option to the which command as follows:
$ which -a command
$ which -a ls

Sample outputs:
which command demo

which command options

From the which(1) command man page:

Option Meaning
--skip-dot Skip directories in PATH that start with a dot.
--skip-tilde Skip directories in PATH that start with a tilde.
--show-dot Don’t expand a dot to current directory in output.
--show-tilde Output a tilde for HOME directory for non-root.
--tty-only Stop processing options on the right if not on tty.
-a Print all matches in PATH, not just the first
-i Read list of aliases from stdin.
--skip-alias Ignore option -i; don’t read stdin.
--read-functions Read shell functions from stdin.
--skip-functions Ignore option –read-functions; don’t read stdin.

On Linux bash defined which as function as follows:

which ()
   (alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@
export -f which

tcsh / csh user can create an alias as follows:

alias which 'alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

In the Korn shell, you can use the whence command for the same purpose:
$ whence ls
$ whence date httpd ls

See also
  • which(1) Linux/Unix command man page

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum