Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

migrated from Apr 28 '12 at 13:46

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

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
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 `.` – LawrenceC 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

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

share|improve this answer

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .