Take the 2-minute tour ×

Let´s say I´m in a directory in ~/Code/proj and there is a binary called proj that I compiled via GCC and the way I can run this program is:

~/Code/proj $ ./proj

How do I push the proj directory to $PATH so from now on all binaries in this directory can be called without the ./ prefix?

share|improve this question
Which platform are you using? –  crazy_prog Dec 17 '11 at 16:13
@crazy_prog: the tags mention Linux. –  Basile Starynkevitch Dec 17 '11 at 16:18
There is security issue putting current directory in the path. let say, you are in /tmp where everybody can drop anything. and you execute ls, it is possible that somebody have dropped malicious ls executable there and instead of what you've expected, ls will do something else. Of course that depends on the order in your path, but generally in snot good idea –  Op De Cirkel Dec 17 '11 at 16:18
Yes, and generally it is better, if having . in your PATH is required (and you should avoid that), to put it at the end of the PATH –  Basile Starynkevitch Dec 17 '11 at 17:00
Hey, you can just add the current directory to the path instead of ., as my solution demonstrates! –  fge Dec 17 '11 at 18:01
add comment

2 Answers

up vote 4 down vote accepted

export PATH="$PATH:$(pwd)"

ie, append your current directory (NOT .!) to PATH.

share|improve this answer
what is the -P do, my version of bash doesn't honor the -P. Good luck to all. –  shellter Dec 17 '11 at 17:52
It means to resolve all symlinks for the path. This is really curious that your pwd version does not support that! I have been using this option for at least three years. –  fge Dec 17 '11 at 18:00
yes, actually, it bombs out my terminal session and closes it ;-) Thanks for sharing, would be good to use if it is available. –  shellter Dec 17 '11 at 18:08
OK, removed it from the solution. Don't forget to accept the answer if it suits you ;) –  fge Dec 17 '11 at 18:13
export PATH="$PATH:$PWD" - shorter, faster, and works in every shell that provides the PWD variable (includes the posixy dash). –  jørgensen Dec 17 '11 at 20:12
show 1 more comment

Pushing a directory into PATH don't means much.

To know what your PATH is just type

echo $PATH

You could change your PATH or put your binary in some directory inside it.

You can temporarily change your PATH with a command like suggested by fge

If your login shell is bash which is often the case, you could edit one of the $HOME/.bashrc or $HOME/.profile files to set your path. (For zsh shell the start-up files are different, and you may need to run rehash after changing things related to your path).

Many Linux distributions give you a PATH containing your $HOME/bin/; then you could create that directory (if relevant) and copy your executable inside it.

I find that having few directories in the PATH is cleaner. I prefer copying my executables and scripts in one single directory like $HOME/bin/

share|improve this answer
add comment

Your Answer


