next up previous contents index
Next: Configuration Files Up: Using the Shell Previous: Environment Variables   Contents   Index


Where Commands Reside: The PATH Variable

When you type a command into the shell, it has to find the program on your hard disk before executing it. If the shell had to look all over the disk, it would be very slow; instead, it looks in a list of directories contained in the PATH environment variable. This list of directories makes up the shell's search path; when you enter a command, it goes through each one in turn looking for the program you asked to run.

You may need to change the PATH variable if you install programs yourself in a non-standard location. The value of PATH is a colon-separated list of directories. The default value on Debian systems is as follows:

/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games

This value is defined in the file /etc/profile and applies to all users. You can easily change the value, just as you can change any environment variable. If you type the command ls, the shell will first look in /usr/local/bin; ls isn't there, so it will try /usr/bin; when that fails, it will check /bin. There it will discover /bin/ls, stop its search, and execute the program /bin/ls. If /usr/bin/X11/ls existed (it doesn't, but pretend), it would be ignored.

You can see which ls the shell is going to use with the type command. type ls will give you the answer /bin/ls. Try it yourself.

Try asking where type itself resides:

$ type type

type is a shell builtin 

type isn't actually a program; it's a function provided by the shell. However, you use it just like an external program.

There are a number of commands like this; type man builtins to read the man page describing them. In general, you don't need to know whether a command is a builtin or a real program; however, builtins will not show up in the output of ps or top because they aren't separate processes. They're just part of the shell.


next up previous contents index
Next: Configuration Files Up: Using the Shell Previous: Environment Variables   Contents   Index
John Goerzen / Ossama Othman