Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question already has an answer here:

When display hidden file and directory in terminal using ls -la it show two directory i.e. . and .. and when list the content of dot(.) directory it contain all file and directories that is in it's parent directory,are it create clone of that file, if yes then there is duplicate files ?

And while running a script we have use that dot directory if we are in directory where it reside like ./script

but not when we run it from another directory like

/Document/myscript/script

why?

share|improve this question

marked as duplicate by Ƭᴇcʜιᴇ007, Kevin Panko, Moses, Tog, Mokubai May 16 at 22: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.

1 Answer 1

up vote 13 down vote accepted
  • The . is same as saying "current directory". So ./script means execute script file in current directory.
  • The .. is same as saying "parent directory" (one directory up).

Also, if you are in / directory, there is no difference between:

/Document/myscript/script

and

./Document/myscript/script

So when you use the dot (. or ..), the path you provide is relative to current\parent directory you are in.

If you use full path, then the path is absolute path to the file.

share|improve this answer
4  
Would I be right in adding that the reason for executing ./script rather than script is that it prevents execution of an identically named script somewhere in your PATH (important if you mistype the script name)? –  Chris H Apr 21 at 16:00
3  
Yes you are correct. ./script will execute script in current directory, while just script will look in PATH. I don't think it will look in current directory if it is not in PATH. –  edvinas.me Apr 21 at 16:11
4  
The PATH on Unix system does not include the current directory (.) as a security precaution. –  David Apr 21 at 17:07
    
what do dots in the middle of paths do? (such as /Documents/./myscript) –  Bogdacutu Apr 21 at 20:18
    
Single dots inside a path have no effect as they are referring to the then current directory. So x/y/./z is the same as x/y/z. Double dots go up one level so, assuming that both y1 and y2 are directories inside directory x, x/y1/../y2/z is the same as x/y2/z –  DoxyLover Apr 21 at 20:22

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