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"
🌐
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)
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....
🌐
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...
🌐
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 ...
🌐
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.
🌐
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)
🌐
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.

Top answer
1 of 6
39

For the sake of completeness ...

  • Just path is a file or directory named path in the current directory.
  • ./path is a file or directory named path in the current directory, with the directory spelled out. The dot directory . represents the current directory, and path is the name of the file or directory within this directory.
  • ~/path is a shorthand for $HOME/path where $HOME is a variable which refers to your home directory. Typically your home directory will be somewhere like /home/you or /Users/you where you is your account name. (The command echo "$HOME" will display your home directory.) The expanded value is an absolute path (unless you have messed up the value of $HOME thoroughly), as indicated by the initial slash.
  • /path is an absolute path which refers to a file or directory named path which is in the root directory /. Every file on Unix is ultimately somewhere in the directory tree which starts with the root directory.

A file name which begins with $ includes the value of a shell variable in its name (like for example $HOME above); you have to know the value of that variable to determine whether it ends up containing a relative or an absolute path. Similarly, ~ at the beginning of a file name gets replaced ("expanded") by the shell to a different string, as outlined above. (Technically, it's possible for a file name to begin with a literal dollar sign or tilde, too; you would then have to quote or backslash-escape that character to avoid having the shell expand it to something else. This is rather inconvenient, so these file names tend to be rare in practice.)

In the following exposition, we refer to the result of any such replacements, and ignore the complication of possible quoting.

Every file name which begins with / is an absolute path (aka full path) which explains how to reach a particular node starting from the root directory. For example, /var/tmp/you/reminder.txt refers to a file or directory reminder.txt (probably a file, judging from the name; but Unix doesn't care what you call your files or directories) which is in the directory you which is in the directory tmp which is in the directory var which is in the root directory.

Every file name which doesn't begin with / is a relative path which indicates how to reach a particular file or directory starting from the current directory. The special directory .. is the parent directory (that is, the directory which contains this directory) and the special directory . is the current directory. So path/there refers to the file or directory there inside the directory path in the current directory; and (hover the mouse over the gray area to display the spoiler)

there/.././and/back/.. is a (wicked complicated) way to refer to the directory and in the current directory, where we traverse the there directory and then move back to the current directory; then stay in the current directory; then refer to the directory back inside the directory and, but then move back to the parent directory of that, ending up with ./and.

In addition to ~/ for the current user's home directory, some shells and applications allow the notation ~them/ to refer to the home directory of the user account them. Also, some web server configurations allow each user to have a public web site in their directory ~/public_html and the URL notation http://server/~them/ would serve up the site of the user account them for outside visitors.

The current directory is a convenience which the shell provides so you don't have to type long paths all the time. You can, if you want to.

/bin/ls /home/you/Documents/unix-101/directories.txt

is a longwinded but perfectly valid way to say (assuming you are in your home directory),

ls Documents/unix-101/directories.txt

You could also say

cd Documents/unix-101
ls directories.txt

and until you cd again, all your commands will run in this directory.

See What exactly is current working directory? for a longer exposition of this related concept.

A "directory" is sometimes called a "folder" by people who are not yet old enough to prefer the former.


Tangentially, don't confuse the directory name . with the Bourne shell command which comprises a single dot (also known by its Bash alias source). The command

. ./scriptname

runs the commands from the file ./scriptname in the context of the current shell instance, as opposed to in a separate subshell (which is what just ./scriptname does). In other words, this command line invokes the dot command on a file scriptname in the dot directory.

The Bourne shell (and derivatives like Bash, Zsh, etc) use single quotes to prevent variable expansion and wildcard expansion, and double quotes to permit variable expansion, but inhibit wildcard expansion in a string. The quoting rules on Windows are different, and generally use double quotes to keep whitespace-separated values as a single string (and % instead of $ for variable substitutions).

2 of 6
22

./ means "starting from the current directory". . refers to the current working directory, so something like ./foo.bar would be looking for a file called foo.bar in the current directory. (As a side note, .. means refers to the parent directory of the current directory. So ../foo.bar would be looking for that file one directory above.)

~/ means "starting from the home directory". This could have different meanings in different scenarios. For example, in a Unix environment ~/foo.bar would be looking for a file called foo.bar in your home directory, something like /home/totzam/foo.bar. In many web applications, ~/foo.bar would be looking for a file called foo.bar in the web application root, something like /var/http/mywebapp/foo.bar.