In simple words, it's a list of directories which will be checked (in order) to see if the string you've entered (like firefox) is the file name in one of them. If it is, the first file found will be executed. Answer from eftepede on reddit.com
🌐
LINFO
linfo.org › path_env_var.html
What is PATH? -- definition by The Linux Information Project (LINFO)
Created June 2, 2006. Updated July 8, 2007. Copyright © 2006 - 2007 The Linux Information Project.
Top answer
1 of 3
32

Run in a terminal:

echo $PATH

or

printf "%s\n" "$PATH"

what you see is a list of directories, looking like:

/home/jacob/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

If you put an executable in either one of these directories, you do not need to set the path to the executable / script, but you can run it by its name as a command.

Executables in $PATH should not have a language extension by convention (although they would work)

Editing your $PATH variable

You can (permanently) add a directory to $PATH by adding the following line to your ~/.profile file (invisible by default, press Ctrl+H in the file manager to make it visible):

export PATH=$PATH:/path/to/dir

More usefull information on environment variables

(such as $PATH) can be found here (thanks for the suggestions @Letizia)

2 of 3
14

$PATH is a environment variable that is file location-related.

When one types a command to run, the system looks for it in the directories specified by PATH in the order specified.

You can view the directories specified by typing echo $PATH in the terminal.

Suppose there is a executable file foobar01.sh present at /home/user/foo1/foo2/foobar01.sh which you want to execute on a regular basis. typing the entire "path" would be time consuming. So we add the directory in to $PATH variable and we can execute foobar.sh directly without even specifying the path.

You can add it to $PATH by typing the following command:

export PATH=$PATH:/home/user/foo1/foo2
Top answer
1 of 2
10

/ is equivalent to //

From the POSIX specification (emphasis added):

3.267 Pathname

A string that is used to identify a file. In the context of POSIX.1-2008, a pathname may be limited to {PATH_MAX} bytes, including the terminating null byte. It has optional beginning <slash> characters, followed by zero or more filenames separated by <slash> characters. A pathname can optionally contain one or more trailing <slash> characters. Multiple successive <slash> characters are considered to be the same as one <slash>, except for the case of exactly two leading <slash> characters.

And:

4.12 Pathname Resolution

...
A pathname consisting of a single <slash> shall resolve to the root directory of the process. A null pathname shall not be successfully resolved. If a pathname begins with two successive <slash> characters, the first component following the leading <slash> characters may be interpreted in an implementation-defined manner, although more than two leading <slash> characters shall be treated as a single <slash> character.

For a nice discussion of exceptions (cygwin and directories) see: How does linux handle multiple consecutive path separators (/home////username///file)?

2 of 2
4

You can add multiple slashes to a directory and it will not change anything. E.g. these three commands all do the same:

cd /home
cd /home/
cd /home//

After any of these my current working directory is is set to /home (check with pwd).

I guess that you have your prompt configured to do something smart and that you ran into unanticipated behaviour. What do you get when you echo $PS1 ?

Check this comment on unix.stackexchange.com which may explain it.

Top answer
1 of 3
53

The :+ is a form of parameter expansion:

${parameter:+[word]} : Use Alternative Value.

If parameter is unset or null, null shall be substituted; otherwise, the expansion of word (or an empty string if word is omitted) shall be substituted.

In other words, if the variable $var is defined, echo ${var:+foo} will print foo and, if it is not, it will print the empty string.

The second : is nothing special. It is the character used as a separator in the list of directories in $PATH. So, PATH="/usr/local/bin:/usr/bin${PATH:+:${PATH}}" is a shorthand way of writing:

if [ -z "$PATH" ]; then
    PATH=/usr/local/bin:/usr/bin
else
    PATH=/usr/local/bin:/usr/bin:$PATH
fi

It's just a clever trick to avoid adding an extra : when $PATH is not set. For example:

$ PATH="/usr/bin"
$ PATH="/new/dir:$PATH" ## Add a directory
$ echo "$PATH"
/new/dir:/usr/bin

But if PATH is unset:

$ unset PATH
$ PATH="/new/dir:$PATH"
$ echo "$PATH"
/new/dir:

A : by itself adds the current directory to the $PATH. Using PATH="/new/dir${PATH:+:$PATH}" avoids this. So sure, you can use PATH="${PATH:+${PATH}:}/usr/local/bin:/usr/bin" if you want to, or you can use PATH="$PATH:/usr/local/bin:/usr/bin" if you prefer. The only difference is that the former might add an extra :, thereby adding your current directory to your $PATH.

2 of 3
11

You're correct, it does mean 'if $PATH exists — and is not null — then add :$PATH'.

You need to check whether $PATH exists because you don't want to add the leading (or trailing) colon if $PATH is undefined. A zero-length (null) directory name in the path, as in :/usr/local/bin:/usr/bin, or /usr/local/bin:/usr/bin:, or /usr/local/bin::/usr/bin, means search the current directory.

Excerpted from man bash:

   PATH   ...
          A zero-length (null) directory name in the value of PATH indicates 
          the current directory.  A  null  directory name may appear as two 
          adjacent colons, or as an initial or trailing colon.
          ...

That's probably not what you want to do.

The following two lines do the same thing:

PATH=":/bin"        # search current directory, then /bin
PATH=".:/bin"
🌐
TechRepublic
techrepublic.com › home › linux 101: what is the linux $path?
Linux 101: What is the Linux $PATH? - TechRepublic
July 1, 2021 - Actually, the Linux PATH is quite simple, in that it consists of all the directories wherein your user can fun commands from anywhere.
Find elsewhere
🌐
Medium
medium.com › towards-data-engineering › understanding-the-path-variable-in-linux-2e4bcbe47bf5
Understanding the PATH Variable in Linux | by Dolamu Oludare | Towards Data Engineering | Medium
December 6, 2024 - The PATH variable in Linux is an environment variable that tells the shell which directory to search for executable files. Not all executable programs exist in this directory.
🌐
RONIN BLOG
blog.ronin.cloud › linux-directories-paths
An Introduction to Linux Directories and the PATH Variable
June 27, 2024 - Now that you understand the Linux ... are set on your system, run the command printenv ... PATH = A list of directories to be searched when executing commands....
🌐
Red Hat
redhat.com › en › blog › navigating-linux-filesystem
A beginner's guide to navigating the Linux filesystem
November 20, 2025 - What is an absolute path? An absolute path is the full path to a file or directory. It is relative to the root directory (/). Note that it is a best practice to use absolute paths when you use file paths inside of scripts.
🌐
Quora
quora.com › What-does-PATH-and-PATH-really-mean-in-Linux-and-Windows
What does $PATH and %PATH% really mean in Linux and Windows? - Quora
Answer (1 of 4): In Linux, PATH is an environment variable that contains an ordered list of directories that will be searched when a non-builtin command is requested. E.g. in bash-type shells, if I type "foo" and my path is "/usr/local/sbin...
🌐
LINFO
linfo.org › path.html
Path definition by The Linux Information Project (LINFO)
A path is the address of an object (i.e., file, directory or link) on a filesystem · Filesystems are hierarchies of directories (also called directory trees) that are used to organize files on computers, on networks, and on storage devices and media (e.g., hard disk drives and CDROMs)
🌐
Astrobiomike
astrobiomike.github.io › unix › modifying_your_path
What the heck is my PATH, and how do I get it to do what I want?
For files, we usually point to where the file is using an absolute or relative path, where “path” here, in lowercase, just means a sort of address in the computer. But for programs that we use often, we usually want to be able to call them without having to provide the path to wherever ...
🌐
Quora
quora.com › What-does-mean-in-a-directory-path
What does '~/' mean in a directory path? - Quora
Answer (1 of 6): In Windows, ~ is a valid folder name. In Linux, it's the symbol for your home folder. (only in a shell though, because you can have a directory with ~ as its actual name, it’s just harder to use from a shell script)
🌐
Wikipedia
en.wikipedia.org › wiki › PATH_(variable)
PATH (variable) - Wikipedia
July 29, 2025 - PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting. Multics originated the idea of a search path.
Top answer
1 of 4
12

The basic concept to grasp here is that PATH can be defined in many places. As @demure explains in his answer, PATH=$PATH:/new/dir means add /new_dir to $PATH, it will not clear the original $PATH.

Now, one reason there are many files is intimately connected with the concept of login and non-login shells. See here for a nice summary. The following is from the bash man page (emphasis mine):

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

When you first log into your system, you start a login shell so bash will read the files listed above. Most distributions set a system-wide $PATH (which applies to all users) at /etc/profile and this is where you should make any changes that you want applied to all users. This is what I have on my Debian:

PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"

Once you have logged in, when you open a terminal you start an interactive, non-login shell. This is what man bash has to say about those:

   When  an  interactive shell that is not a login shell
   is started, bash reads  and  executes  commands  from
   /etc/bash.bashrc and ~/.bashrc, if these files exist.

So, those files are read every time you open a new terminal. Your filnal $PATH is the combination of the values in all files. In a typical situation, you log in using a graphical log in manager and start a new session. At this pòint your $PATH is whatever was defined in the various profile files. If you open a terminal, then you are in an interactive shell and the different bashrc files are read which may append things to the $PATH.


To summarize, all you really need to know is that you can make changes to your user's $PATH by editing $HOME/.profile.

2 of 4
4

In your home dir, it would be .bashrc, not .bash.rc.
The system wide config is /etc/bashrc not /etc/.bash.rc.

Unix and linux do not use \some\path\here file paths, they use /some/path/here file paths. \ is an escape character, and is used to disable other special characters.

You could edit your $PATH by adding these to lines to your ~/.bashrc (~ means your home dir)

PATH=$PATH:/usr/local/bin:/some/other/path
export PATH

Where

  • $PATH preserves anything already set to the PATH.
  • : separates entries.
  • And the two directories are examples (you don't need the :/some/other/path part)

I would not suggest editing your system wide /etc/bashrc if you only need changes for yourself.