Learn
Environment
PATH Environment Variable

PATH is an environment variable that stores a list of directories separated by a colon.

What happens when you type this command?

$ echo $PATH /home/ccuser/.gem/ruby/2.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin

Looking carefully, echo $PATH lists the following directories, separated by :

  1. /home/ccuser/.gem/ruby/2.0.0/bin
  2. /usr/local/sbin
  3. /usr/local/bin
  4. /usr/bin
  5. /usr/sbin
  6. /sbin
  7. /bin

Each directory contains scripts for the command line to execute. The PATH variable simply lists which directories contain scripts.

For example, many commands we’ve learned are scripts stored in the /bin directory.

/bin/pwd

This is the script that is executed when you type the pwd command.

/bin/ls

This is the script that is executed when you type the ls command.

In advanced cases, you can customize the PATH variable when adding scripts of your own.

Instructions

1.

In the command line, type:

echo $PATH

This prints the PATH variable.

2.

Let’s confirm that most of the terminal commands we’ve learned so far are in /bin/.

Type the following into the terminal:

/bin/pwd

This should have the same output as the pwd command.

3.

Type:

/bin/ls

This should have the same output as the ls command.

Folder Icon

Sign up to start coding

Already have an account?