6

Whenever you type ls -a into the command prompt, you usually get all of your folders, files, and then you see that the first two entries are . and ..

Just curious, but what is the significance of these two entries?

Shawn J. Goff
  • 46,081
  • 4
    To not list . and .. you can use ls -A. – Nykakin Apr 24 '13 at 12:01
  • Note that they are not necessarily the first ones, it just so happens that the . character, in most locales, sorts before the characters usually used as the first character of a file name (but there still are plenty of characters that sort before .). – Stéphane Chazelas Jan 02 '16 at 21:48

3 Answers3

14

. is the relative reference for the current directory.
.. is the relative reference for the parent directory.

This is why cd .. makes the parent directory the new working directory.

Shawn J. Goff
  • 46,081
  • 6
    This also explains the ./ that you have to type when you want to run a executable from the current directory. It's the equivalent to typing /the/full/path/to/the/executable. (had one of these "ahh" moments when I realized that :) ) – alextsc Oct 01 '11 at 19:58
  • 2
    In most cases "." and ".." are also absolute references to the corresponding INODE (or other internal structure element of the used filesystem) of the current or "below" directory. – Nils Oct 01 '11 at 20:53
  • 1
    one exception to this rule is the root dir / where . and .. both point to the current dir. – Sirex Oct 03 '11 at 06:55
  • Sirex's comment is important because it's what allows you to ../../../../../../../../../../../../../../.. for as long as you want and not break anything. – Dason Oct 31 '11 at 05:19
9

. and .. are hard links to the current and the parent directory (/ is the parent of itself).

With the -a option ls shows all inodes in the current directory, i.e. also the hidden files which filenames begin with ad dot, therefore . and .. are shown.

jofel
  • 26,758
  • Well, my question is duplicate. In the link that you posted, there is an answer for my question. Thanks by the way. – yfklon Apr 24 '13 at 11:57
-2

you must be knowing that Directory is nothing but a file that points to some list of files, basically it is a pointer, may be hidden or not. in similar way . and .. are the pointer which point to Uppermost directory and upper directory respectively. that is why i think when we execute

ls -a

command, these are displayed!

Anthon
  • 79,293