PATH
?PATH
is an environment variable in Unix-like operating systems (including Linux and macOS) and Windows. It specifies a list of directories that the system searches for executable files when you type a command in the shell.
PATH
PATH
variable is a colon-separated list of directories.Example of a typical PATH
value on a Unix-like system:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/home/user/bin
PATH
is UsedWhen you enter a command like ls
or python
, the shell looks in each directory listed in PATH
for an executable file with that name. If it finds one, it runs the command. If not, it returns an error indicating the command was not found.
PATH
You can view the current PATH
using the echo
command:
echo $PATH
To add a directory to PATH
in a bash shell, you can modify it like this:
export PATH=$PATH:/new/directory/path
Suppose you have a custom script located in /home/user/scripts
and you want to be able to run it from anywhere without typing the full path. You would add /home/user/scripts
to your PATH
:
export PATH=$PATH:/home/user/scripts
To make this change permanent, you can add the above line to your ~/.bashrc
or ~/.bash_profile
file.