Locating Executables with PATH
Explore how the PATH environment variable helps the shell locate executable programs. Understand how to create, make executable, and run scripts from anywhere by managing their locations or modifying PATH. This lesson helps you control command execution and placement for practical command-line use.
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. ...