How do you add any current directory './' to the search path for executables in Linux?
6 Answers
I know this is an old answer, but if anyone else stumbles across this question via Google like I did, here's a more detailed explanation.
If you want to make it so that search path contains the value of pwd
at the time you set the search path, do:
export PATH=$PATH:$(pwd)
So, if pwd
is /home/me/tmp
, PATH will be set to $PATH:/home/me/tmp
However, If you want it so that whatever your present working directory is at the time you execute a command (ex; the value of pwd
at any given time is in the search path), do:
export PATH=$PATH:.
So, if pwd
is /home/me/tmp
, PATH will be set to $PATH:.
. If your present working directory contains a script called foo
, then it would be fount in your PATH. If you change directories to one that does not contain foo
, "foo" will not be found in the PATH any more.
You should note that having your present working directory in your PATH is a potential security risk, however.

- 939
- 6
- 7
-
21always add the . at the end of path... not the beginning. putting it at the beginning is the biggest security risk. because you can replace standard commands like ls. Very bad practice. Put it at the end, then standard commands will always be issued first. – DiamondDrake Mar 28 '16 at 22:50
-
3Thanks @RickeyWard, you're absolutely right. I edited the answer to reflect your suggestion. – Justin Doyle Mar 30 '16 at 15:18
-
9The risk here is very real. If I create a malicious executable file named after a common utility (`ls`, etc) and trick you into visiting the directory it's in, you are likely to run it and get exploited. This doesn't apply as easily to single-user hosts but it's still an unnecessary risk. I'd recommend against any relative directories in `$PATH`. If you have a bunch of commands in a directory that you only use sometimes, you're better off writing a quick script that adds it (explicitly) to the path. – Mark Nov 01 '17 at 14:53
-
1Alternative viewpoint, by putting the . at the end of the path, you introduce the very real risk that you will run executables or scripts that you did not intend, simply because a script with the same name exists somewhere else in the path. – Sean Worle Apr 09 '19 at 00:16
-
1Right, that's exactly the security risk I was referring to, and the one that Mark laid out explicitly. If you append it to the end of $PATH, you mitigate the risk of overwriting common utilities, but even at the end of $PATH, there's still some risk involved. – Justin Doyle Apr 10 '19 at 21:15
-
After reflecting on it some more, it's such a security risk that i actually didn't upvote this answer. Let's focus more on the answers that are less convenient but overall better, in my humble opinion. – John Fantastico Aug 07 '20 at 14:21
If you want to permanently add the directory you're currently in to the PATH variable you can use
$ echo "export PATH=\$PATH:$(pwd)" >> ~/.bashrc
which will expand $(pwd)
to the string literal of your current directory and append the quoted line to your bashrc which is loaded when you start your terminal. Note the \
in \$PATH
is needed to escape the expansion of $PATH
to its current value.
$ pwd
/path/to/suuuuuuuuuuuuuuuuuuuuper/long/foo/directory/bin
$ echo "export PATH=\$PATH:$(pwd)" >> ~/.bashrc
$ tail ~/.bashrc -n 1
export PATH=$PATH:/path/to/suuuuuuuuuuuuuuuuuuuuper/long/foo/directory/bin

- 1,288
- 15
- 28
For the current directory, you can just use a zero-length (null) directory name. You can use an initial or trailing colon, or a double colon. This is from the bash manpage, man bash
:
PATH The search path for commands. It is a colon-separated list of
directories in which the shell looks for commands (see COMMAND EXECUTION
below). 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. The default path
is system-dependent, and is set by the administrator who installs bash.
A common value is
``/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin''.

- 1,494
- 1
- 16
- 23
-
3I actually found this answer most informative as leaving the initial or trailing colon in your PATH may go unnoticed but eventually lead to some serious security vulnerabilities described in the comments above. – Theta Jun 12 '21 at 14:28
Um...that didn't work for me. I would do
export PATH=$(pwd):$PATH
The command previously posted literally just adds the dot.

- 134
- 2
- 10
This is an old question, but I thought I'd add to it for those using the CSH or TCSH.
Adding the following to your .cshrc or .tcshrc will add the current directory to the environment path variable.
setenv PATH {$PATH}:.

- 73
- 4