Where Is the Command?
Linux uses your PATH variable to find a command that you enter on the command-line.
- Commands are generally (but not always) files that are in a directory on your system.
- Your PATH variable is a colon-separated list of directories in which the shell searches to find the file that matches the name of the command you enter.
- Show the value of your PATH variable to see the directories that will be searched; it searches each in order until the file is found, and then that file is executed.
- Note: when searching for a command, it will only consider files that have execute permission.
- There are many types of files that can be a command. We have already seen executables (where are they?) and have mentioned the idea of a shell script (more later).
- If your PATH has this in it:
:.:
- What directory will it search?
- Does your path have this? Does it have
::
? Note: they do the same thing; what is it?
So, if the shell searches until it finds the command, how can you tell where it is?
In other words, if you have 2 files, both are executable, and both are named mycmd, how can you tell which is being executed?
There are a number of commands that will tell you this, based on your system. Which ones work on your flavor of Linux?
You may have more than one - note the differences.