10

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?

0

1 Answer 1

18
  • 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.

5
  • 6
    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, 2014 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.
    – ek9
    Apr 21, 2014 at 16:11
  • 4
    The PATH on Unix system does not include the current directory (.) as a security precaution.
    – David
    Apr 21, 2014 at 17:07
  • what do dots in the middle of paths do? (such as /Documents/./myscript)
    – Bogdacutu
    Apr 21, 2014 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, 2014 at 20:22

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