Linux Command Lookup and the PATH Variable
Where does a command come from?
Some commands are implemented inside the shell (builtins); others are executable files. cd is a builtin that changes the current shell’s directory. ls is usually an external executable. Bash can also recognize aliases (shortcuts expanded while parsing) and functions (named groups of commands); these can change what a typed name means.
In a clean Bash session the result is builtin then file. If you have configured an alias or function, the answer for ls can change. Run type ls to inspect the active definition.
PATH is a search list
PATH is a shell variable containing directory names separated by colons. In ordinary Bash mode, after alias processing, a simple name is normally resolved as a function, then a builtin, then an executable found through PATH (possibly using a cached location). A name with a slash identifies a path instead of triggering PATH search.
The first line is typically cd; the second may be /usr/bin/ls or another path. command -v reports how the shell recognizes a name, not necessarily a filename. type -a ls can list multiple definitions.
If the reported kind is alias or function, first inspect the definition rather than reinstalling a package or changing the search list. A shell builtin can work without a matching executable in any search directory. The lookup result and a program’s actual behavior are two different pieces of evidence.
For example, /usr/bin:/bin contains two search locations; your session may have more. $PATH requests the value of PATH. Double quotes keep the expanded text as one argument. No configuration is changed by this command.
Do not add the current directory or unknown writable folders to PATH to fix command-not-found errors. First check the name, command availability and trusted installation instructions.
Practice
Compare type -t pwd with command -v pwd. Is the result necessarily an executable path? Inspect type -a pwd for alternatives.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Command lookup and PATH — Knowledge Check
Apply the command-line concept in a safe beginner lab.
What does type -t cd normally print in Bash?
What separates directories in PATH?
What can command -v cd return?
Does ./tool require PATH lookup?
What is a good first action if a command is missing?