Linux which command
Linux which command
In this tutorial, you will learn about which Linux Command with examples. The which
command in Linux is used to locate the executable file of a command or program by searching through the directories listed in the system’s PATH
environment variable. It is used to know which command is executed by the shell. It locates the command/utility and prints the pathname to the console.
which Command Syntax
The which command prints the path of the command executed by the shell. The general syntax of the command is as follows:
$ which [flags] command_name
To know more about the command, type the man command
$ man which
Example
For example, to know the pathname of the pwd command executed by the shell.
Launch the Terminal/Konsole and type the following command.
$ which pwd
When you type a command (like ls
or python
) in the terminal, Linux looks through the directories defined in the PATH
variable to find the executable file.
The which
command tells you the exact location (path) of that executable.
The shell would execute the pwd command from /usr/bin/pwd
That’s it.