Setting your search path

The basics of the search path

(Since the notion of the search path is critical for your working environment, we're going to spend a few pages discussing it. You'll thank me for this some day. Really.)

Just as it does in the Windows world, the PATH shell variable represents your command search path -- an ordered, colon-separated list of directories that are searched, left to right, for every command that you execute. Each user has the freedom to define their own personal search path, which you can display as shown below (which also shows a fairly typical example of a search path):

$ echo $PATH

Typically, the search path begins with a small number of standard system directories such as /bin, /usr/bin and /usr/X11R6/bin, possibly some extra directories for third-party or locally-installed software such as /usr/local/bin and, finally, perhaps a few personally-chosen directories of your own at the end. And who decides what your search path will eventually look like? Your personal search path is typically the end result of piece-by-piece construction by a number of programs and login-time configuration files such as:

  • /bin/login
  • /etc/profile
  • /etc/profile.d/*.sh
  • ~/.bash_profile

The sample list above just emphasizes how many files and programs may have a hand in building the final search path, but it's important to note that you, the user, have the final say since it's your personal .bash_profile startup file that is consulted last.

If, at any time, you want to extend your search path temporarily just for the duration of the rest of this login session, you can add a new entry to the end at the command prompt with (for example):

$ PATH=$PATH:/usr/games

If, however, you want to make a permanent change, you should do this in your personal .bash_profile, and your new path will take effect at the next login.


If you want to execute a program from a directory that is currently not in your search path, there's no need to add that directory to the path. Just type the fully-qualified name of the executable, as in:

$ /usr/games/fortune


Regardless of what anyone else tells you, there is little value in exporting your PATH variable. This variable is used primarily for locating executable commands, not for passing any useful information to them. It probably won't hurt to export PATH, but it's unlikely to have any benefit.