Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

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

gcc -o demo demo.c
./demo

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, 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.

2  
How does this relate to Ubuntu? –  Mitch Sep 24 '13 at 6:30
1  
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
add comment

4 Answers 4

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
add comment

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
add comment

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
add comment

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
add comment

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