When you enter a command, the operating system has to search for that program.
The path defines the directories which the system will search.
To find out your current path, enter the command: echo $PATH
The output may be: /usr/bin:/bin
The path is a list of directories separated by colons.
The path /usr/bin:/bin means that when you enter a command, the shell will
search for the program in the directory /usr/bin and then in the directory
/bin. If the program is stored in either of these 2 directories, it will
run; if the program is not stored in either of these 2 directories, you will
only get an error message.
To change the path to /bin, use the command: PATH=/bin
To add the directory /usr/local/bin to the existing path, use the command:
PATH=$PATH:/usr/local/bin
Note: the current directory is NOT automatically included in the search path.
If there is an executable program called greatgame in the current directory,
entering the command, "greatgame" results in the error message "command not
found". You can see the file, but the shell cannot. To run the program, enter
the command "./greatgame".
Without a path, you would have to know where every program is stored on your
system. To use the cal program, you would have to type /usr/bin/cal
; to use the date program, you would have to type /bin/date ; etc
Exercises:
What is your current search path? _________________________
Change the path to include /usr/bin , /bin , /usr/sbin .
Verify that the search path was changed by entering the command: echo
$PATH
Change your path so that it includes ONLY your home directory.
Verify that the search path was changed.
Try to get a directory listing - what happens? _________________________
Now try to get a directory listing using the command: /bin/ls. Did
this work? _____
Logout and login again. What is your search path now?