[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedMay 2, 2023

How to use which command.

How to use which command.

In this tutorial, we will cover the Linux which command.

Linux which command is used to identify the location of a given executable that is executed when you type the executable name (command) in the terminal prompt. The command searches for the executable specified as an argument in the directories listed in the PATH environment variable.

 

What is PATH

In Linux, PATH is an environmental variable that tells the shell and other programs which directories to search for executable files. It consists of a list of colon-separated absolute paths to directories containing the executables.

To view the contents of your PATH variable, use the echo command with $PATH as an argument:

echo $PATH

The output will look something like below:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

 

How to Use the which Command

The syntax for the which command is as follows:

which [OPTIONS] FILE_NAME...

For example, to find the full path of the ping command , you would type the following:

which ping

The output will be something like this:

/usr/bin/ping

You can also provide more than one arguments to the which command:

which netcat uptime

The output will include full paths to both netcat and uptime executables:

/bin/netcat
/usr/bin/uptime

The search is done from left to right, and if more than one matches are found in the directories listed in the PATH path variable, which will print only the first one. To print all matches, use the -a option:

which -a touch

The output will show two full paths to the touch command :

/usr/bin/touch
/bin/touch

Usually one of the executables is only a symlink to the other one, but in some cases, you may have two versions of the same command installed in different locations or totally different commands using the same name.

 

Conclusion

The which command is used to locate a command by searching the command executable in the directories specified by the environmental variable PATH.

Keep reading
How to List Users in Linux.
September 11, 2023

How to List Users in Linux.

How To List Users In Linux. This tutorial will show you how to list users in Linux systems. Have you ever wanted to list all users in your Linux system or to count the number of users in the system? There are commands to create a user, delete a user, list logged in users, but…

Read article
How to Install Asterisk on CentOS 7
September 8, 2023

How to Install Asterisk on CentOS 7

How To Install Asterisk On CentOS 7 This tutorial will guide you through the steps required to install Asterisk 15 on CentOS 7. Disable Selinux If SELinux is set to enforcing mode, Asterisk will not function correctly. To disable SELinux security features, open the /etc/selinux/config file and set…

Read article
How to Install R on CentOS 7
September 8, 2023

How to Install R on CentOS 7

How To Install R On CentOS 7 This tutorial will teach you how to install R on CentOS 7 and how to install R packages from the official Comprehensive R Archive Network (CRAN) . Installing R on Centos At the time of writing the latest stable version of R is version 3.5. To install…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00