A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/linux-unix/which-command-in-linux-with-examples/ below:

How to Display Path of an Executable File in Linux | Which Command

How to Display Path of an Executable File in Linux | Which Command

Last Updated : 11 Jul, 2025

In Linux finding the exact path of an excutable file can be crucial for the system adminstration, scripting and as well for troubleshooting. The `which` command helps with providing a simple and effective way to locate the executable files within the directories that are listed in your system.

In this article, we are going to discuss on what is which command in linux, its options to use, examples of which command. How to display path of executable file in linux, discussing the practical examples and the differences of where and which command:

What is Which Command in Linux?

The `which` command in Linux is used to locate the executable file associated with a given command. When you enter a command in the terminal, `which` helps identify which executable file will be executed when that command is invoked. It searches through directories listed in the user's `PATH` environment variable and returns the path of the first executable file it finds that matches the specified command. This command is particularly useful for troubleshooting and understanding the execution flow of commands within the Linux operating system.

which command in Linux is a command that is used to locate the executable file associated with the given command by searching it in the path environment variable. It has 3 return status as follows:

Syntax of `Which` Command in Linux

The basic syntax of the which command in Linux is straightforward. It follows the following format:

which [filename1] [filename2] ...
Options of Which Command

The following are the options of which command:

Option Description Example -a, --all Display all matches found, instead of just the first which -a python --skip-alias Skip aliases and proceed searching which --skip-alias ls -h, --help Display help information which --help -V, --version Display version information which --version Example of Which Command

In this following example, we are finding the path of date command (executable file) using which command:

which date
How to Display Path of an Executable File in Linux?

It is basically used to find the location of the executable file associated with the command.

For Example: To find the location of the "cd" command, we use the following command 

which cd
Pratical Examples and Options of the `which` Command in Linux

The following are the practical examples and options of the which command in linux:

1. Using `-a` to display all the occurrences of the file.

Simple `which` command will display the path of the first occurrence, but if we want ot display all the occurrences of the file we can use `-a` option.

For Example: If we want to display all the occurrences of the `python` file.

which -a python
2. Checking Command Aliases

For Example: If we want to check whether the command `ll` is an alias or not.

which -a ll
3. Using `-v` to display more verbose output.

For Example: If want o display more verbose and additional information of `echo` command.

which -v echo
4. Display help information of the `which` command
info which
Importance of which command

The following are the importance of which command:

Functionalities of which Command

The following are the functionalities of which command:

Why use which command?

The following are the some of the reasons and insights to use which command:

Difference between Where and Which Command

The following are the difference between where and which command:

Aspect where Command which Command Purpose Used to locate files and directories Used to locate executable files Operating System Typically found in Windows systems Typically found in Unix-like systems Output Provides a list of all matches Provides the path of the first match Usage Example: where java Example: which python Conclusion

In this article we have discussed about `which` command that is mainly used to locate the executable file associated with the given command. We have discussed Options available and there usage. One can easily understand the working of `which` command by going through this article. we come with discussing the frequently asked questions on linux after this conclusion section.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4