[email protected]Mon – Fri 9:00AM – 5:00PMLinkedInXFacebook
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 Implement Network Segmentation and Resource Isolation in Linux.
February 6, 2024

How to Implement Network Segmentation and Resource Isolation in Linux.

How to Implement Network Segmentation and Resource Isolation in Linux. Securing and managing networks in a Linux environment involves advanced practices like network segmentation and resource isolation. This guide explores these concepts, providing detailed instructions and examples for…

Read article
How to open or close ports in Linux.
February 6, 2024

How to open or close ports in Linux.

How to open or close ports in Linux. Effectively managing ports on your Linux system is crucial for both security and service accessibility. This comprehensive guide will provide a detailed walkthrough on opening and closing ports using the robust tools iptables and ufw. Understanding these…

Read article
How to use ypdomainname command.
January 23, 2024

How to use ypdomainname command.

How to use ypdomainname command. In the realm of Linux networking, the ypdomainname command plays a crucial role in the context of the Network Information Service (NIS). NIS, formerly known as Yellow Pages, is a distributed database service that facilitates the sharing of network configuration and…

Read article
Get in Touch

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

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

Get Started →Contact Us
[email protected]Mon – Fri 9:00AM – 5:00PM