# How to Get the Path of a Linux Command?

A Linux command that you run from a terminal window can be built-in (a part of the system), a function (an application that runs when you enter certain commands), an alias (another name for a command), or an external executable (a program that you download). You can use the which, command, whereis, whatis, and type tools to determine what each one is and where they are located.

We will look at the which, command, types, and whereis commands as they are usually found in most Linux-Based OSs.

So let’s explore how to get the path of a Linux command in this article.

## PATH Environment Variable

Before we get into the details of the utilities, let us first understand that the applications, such as our shell (the program that runs when we type commands), searches for the commands in a list of folders that are stored in an environmental variable called PATH. Each folder is separated by a colon ":" symbol.

We can see what is inside this variable using the echo function.

### Command

$echo$PATH


### Output

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


When we install an executable file on our computer, so that we can run it from anywhere, we must ensure that the PATH environment variables include the location of the executable.

We can temporarily change the PATH variable by typing this command

### Command

$export PATH=$PATH:/newdir/path
$echo$PATH


### Output

/sbin:/bin:/usr/sbin:/usr/bin:/newdir/path


The above created PATH will be reset when you restart your computer.

We can change the PATH environment variables permanently by editing the.bashrc file.



### Output

/usr/bin/echo


When we type the echo command into our terminal window, it will execute the echo executable file located at /bin/ directory.

Furthermore, the which command has an option -a which will print out all matching paths −



### Output

php: /usr/bin/php /usr/lib64/php /etc/php.ini /etc/php.d /usr/include/php /usr/share/php /usr/share/man/man1/php.1.gz


We can use the -b parameter to display just the binaries.



### Output

php: /usr/share/man/man1/php.1.gz


## type Command

Type commands can not only show the paths of Linux commands, but they can also determine whether the targets are internal, functions, aliases, or external executables.

Let's use type command with -p parameter to see the path of supplied Linux Command −



### Output

echo is a shell builtin


If we use the -a option, it shows the command description, executable type, and the full file name −



### Output

builtin


The above command has output builitin, as echo is type of builtin file.



### Output

file


## command Command

Another useful tool for finding the location of a Linux command is the command command.

This tool lets us know whether we're dealing with an executable file, or an alias command.

The command having two option “-v” and “-V”, where “-v” gives output in just as a result and “-V” option provides output in sentence format.



### Output

php is /usr/bin/php




### Output

echo is a shell builtin


We must add the -v or - V parameter.

If not, it will execute the Linux command that we provide.

### Command

\$ command ls


### Output

command filebeat-6.4.1-x86_64.rpm test.pcap config pmgo pmta4.0.zip


## Conclusion

We can look up the location of a Linux command using the commands - which, command, type and whereis. Some utilities display more information than others.

We've seen in this tutorial that there are a few caveats when using certain commands, but basically, we can use these tools to get more information about a particular Linux utility.