Locating Executables with PATH
Learn how to locate executables with the PATH variable.
We'll cover the following...
An overview of PATH
When we type commands like cd
or ls
, we’re executing a program. The PATH
environment variable contains a colon-delimited list of directories the OS uses to look up executable programs.
We print out the value of the PATH
variable with echo
:
$ echo $PATH
The which
command tells us where an executable is located on the filesystem by looking through all the directories in the PATH
and displaying the first instance it finds. Let’s try it out with the ls
command:
$ which ls
Use the terminal below to practice these commands.
According to this output, the ls
command is located at usr/bin/ls
. That directory is one of the entries on our PATH
of executable files, which is why we can execute it from anywhere on our filesystem. Many of the commands we’ve used so far are ...