The PATH variable tells the shell where to look for executable commands. When you type a command, the shell searches these directories in order.
# View current PATH
echo $PATH
# See which directories are searched
echo $PATH | tr ':' '\n'
cd)# Find where a command is located
which command_name
which ls
which python
# Show all locations of a command
type command_name
type ls
type cd # Shows it's a shell builtin
# More detailed information
type -a command_name
To add a directory to PATH (temporary - only for current session):
# Add directory to beginning of PATH
export PATH="/new/directory:$PATH"
# Add directory to end of PATH
export PATH="$PATH:/new/directory"
# Example: Add current directory to PATH
export PATH=".:$PATH"
Add the export command to your shell configuration file:
~/.bashrc or ~/.bash_profile~/.zshrcNext: → Shell Configuration Files
Previous: ← Command Line Editing
Lesson Home: ↑ Lesson 3: History & Variables
Course Home: ⌂ Introduction to Linux