Menu
Coddy logo textTech

The PATH Variable

Part of the Fundamentals section of Coddy's Terminal journey — lesson 61 of 82.

The PATH variable is one of the most important environment variables in your system. It tells the shell where to look for executable programs when you type a command.

When you run a command like ls or cat, the shell doesn't magically know where these programs are stored. It searches through a list of directories defined in PATH. View it with:

echo $PATH

You'll see something like this:

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

Each directory is separated by a colon (:). When you type ls, the shell checks each directory in order: first /usr/local/bin, then /usr/bin, and so on until it finds the ls program.

If a program isn't in any of these directories, you'll get a "command not found" error. This is why understanding PATH matters.

When you install new software or create your own scripts, they need to be in a directory listed in PATH, or you'll have to type the full path to run them.

You can find exactly where a command lives using which:

which ls

This shows the full path to the program that runs when you type that command.

challenge icon

Challenge

Easy

Use the which command to find the full path to the cat program.

The which command searches through the directories listed in your PATH variable and shows you exactly where a command's executable file is located.

Your output should display the full path to the cat program (something like /usr/bin/cat or /bin/cat).

Hint: The command format is which command_name

Cheat sheet

The PATH variable tells the shell where to look for executable programs. View it with:

echo $PATH

The output shows directories separated by colons (:):

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

When you run a command, the shell searches through these directories in order until it finds the program.

To find the exact location of a command, use which:

which ls

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals