Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

This question already has an answer here:

While I was executing a C program in terminal I wrote:

gcc -o demo demo.c

Actually my doubt is why we write ./ before demo and what does it mean?

share|improve this question

marked as duplicate by Warren Hill, Alaa Ali, Oli Sep 24 '13 at 13:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

How does this relate to Ubuntu? – Mitch Sep 24 '13 at 6:30
It means "in the current directory". We do this so the operating system recognizes it is a file, not a command. – Joren Sep 24 '13 at 7:29

When we execute any command in the terminal it is going to look for it in the PATH environment variable. By using ./ (relative path) we are telling the shell to look for that command in our current directory.

Check echo $PATH

There are two way to execute any commands

  1. Putting its path in the PATH environment variable
  2. Using the full path or a relative path to that programme (Ex. /opt/xyz/bin/someprogramme )
share|improve this answer

When bash interprets the command line, it looks for commands in locations described in the variable $PATH. To see it type:

echo $PATH

Normally, he current directory is not in that list. The reason for not having the current directory on that list is security.

The ./ says: look in the current directory for my command rather than looking at all the directories specified in $PATH.

More about:

share|improve this answer

You put "./" before every program you wish to execute.

Otherwise the terminal doesn't know what to do with "demo" file

share|improve this answer

The "./" before a file name stand for "execute this file in th current directory" if the file that you want to execute is not in the same directory you are in you will need to specify the path o the file like this:

Xxxxx@xxxx /Documents/filetoexecute

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.