which command is a Linux utility that is used to locate the executable file associated with a given command by searching through the directories listed in the
PATH environment variable. The
which command is very useful in situations where you need to know the exact location of a command, especially when you are working with multiple versions of the same command.
The syntax for the
which command is as follows:
which [options] [command]
options are any of the available options for the
which command, and
command is the name of the command that you want to find the location of.
For example, to find the location of the
ls command, you would run the following command:
This will return the absolute path of the
ls command, which is usually
You can also use the
which command to find the location of a command that is not in your
PATH environment variable by specifying the full path to the command:
This will return the full path to the
mycommand executable file.
The following table lists the available options for the
||Displays all matches for the command, rather than just the first one.|
||Ignores case when searching for the command.|
||Displays the locations of the executable files, without running them.|
||Changes the default
||Displays the version number of the
||Skips any aliases and functions that may be defined for the command.|
||Skips any functions that may be defined for the command.|
which command does not return the expected result, there are a few things that you can try:
- Check your
PATHenvironment variable to make sure that the directory containing the command is included.
- Check that the command is actually installed on your system.
- Try using the
locatecommand to search for the command if it is not in your
whichcommand only searches for executable files, not shell built-ins or aliases.
whichcommand can be used in shell scripts to check for the existence of a command before attempting to run it.