Take the 2-minute tour ×

When I compile e.g. x.c by:

GCC x.c -o x

To execute result I have to write:


And just typing:


Fails with this message:

x: command not found

This means Linux does not search current directory for it! Is there (I'm sure there is) any reasonable issue behind this behaviour?

share|improve this question
Because it's the rules. –  Daniel R Hicks Apr 28 '12 at 21:39
@DanH: Then explain "the rules" please. –  Torben Gundtofte-Bruun May 15 '12 at 15:03
add comment

migrated from stackoverflow.com Apr 28 '12 at 13:46

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 12 down vote accepted

Because by default, the current working directory is not in the PATH variable.

This is a security/convenience measure. If you have binaries/scripts called e.g. cd, ls, etc. in your current working directory, it would be very annoying if they were run by default.

share|improve this answer
The answer is only partly correct. The problem could be surrounded if the current directory was only used as last option. Then standard tools would still be found first. –  user unknown Apr 28 '12 at 16:05
Also, shell builtins take precendence (i.e. when you type cd in bash, it executes a routine internal to bash and not /bin/cd) unless you prepend with `.` –  ultrasawblade Apr 28 '12 at 21:43
One of the original *nix security measures, it forces system or admin compiled binaries that are in the system assigned path command to be executed. Nothing so bad as someone to log in as root on a help desk question, go to a user directory, type ls and find they loaded a bomb left by a user. –  Fiasco Labs Apr 28 '12 at 22:03
@userunknown: And the first time you typoed sl, you've got the same problem. Only trusted directories should be in $PATH and relative paths like . are never a trusted directory for an interactive shell. –  user35138 Apr 28 '12 at 22:35
@Basic: If I type rm -r target when I meant rm -f target there is usually no difference. If I type rm -f target when I meant rm -r target, either there's no difference or removal outright fails. Furthermore, I think every time before I type rm, especially if I'm adding -f or -r or a glob - it's a dangerous command by its nature. No one thinks before lsing. –  user35138 May 8 '12 at 18:30
show 3 more comments

It means that the current directory is not in the $PATH variable.

share|improve this answer
add comment

You can fix this by adding the current directory (represented by a single dot) to the PATH environment variable.
The way to do it depends on the shell you are using.
if you are using bash, you can add the line export PATH=$PATH:. to the .bashrc file in your home directory.
if you are using csh or tcsh add the line set PATH = ($PATH .) to the file .cshrc in your home directory.
IMHO, for a home desktop computer this is an acceptable thing to do - security wise.

share|improve this answer
I did not know we can add . to PATH, however, doing this will decrease security, right? –  Yasser Zamani Apr 29 '12 at 6:04
add comment

Your Answer


