36

when I used ls -a to view hidden files in folder there were 2 hidden files created by default what is the significance of this two files . and ..?

ls -a

Produces

.  ..
Marco Ceppi
  • 48,101
  • I use them a lot when I do an ls -la since it will show me the permissions and ownership on the directory I'm in and the directory above the one I'm in. – Marco Ceppi Jul 28 '11 at 20:43
  • i don't have enough rep here to vote to close, but I've put a flag on this question as it's very much a question that can be answered in 3 seconds by searching google (and because there was a recent discussion about questions that are too easy on SO blog). – zzzzBov Jul 29 '11 at 00:30
  • 2
    ^zzzzBov Thank you in Spanish for your generosity. – Vishwanath Dalvi Jul 29 '11 at 12:31

4 Answers4

42

. is the current folder.

.. is the folder above the current folder - the folder that contains the current folder.

You will sometimes see that single dot in use when someone wants to run a script from their home directory. For instance: ./install-app.sh. That means the install-app.sh file is in the current directory. It would be just as valid to do /home/username/directory/install-app.sh. The same way, you could also do ../install.app if the file is in the parent directory. The reason it's this way is not only for navigation, but also that it shouldn't be possible to accidentally hide system applications simply by misnaming a file in your home directory.

NotTheDr01ds
  • 17,888
dv3500ea
  • 37,204
  • 100% correct. Think of them as hooks, that are in every single directory. They are used purely for navigation. You will find that this isn't just a linux standard, but on windows as well. Probably the same on unix and mac as well, but i've never played around in either of their command prompts. – Ctuchik Jul 28 '11 at 19:45
  • 1
    cd / ; cd .. :P – htorque Jul 28 '11 at 20:59
  • 1
    It's the same on FreeBSD too, so I imagine it is also that way on mac, since mac is based on Darwin BSD. – Azendale Jul 28 '11 at 21:04
  • htorque: are you a religious person perhaps? :) – Jo-Erlend Schinstad Jul 28 '11 at 21:08
  • It's on Mac OS X (which works just like any other Unix, though the GUI hides some of it). Mac OS Classic did not have them; :: was used for previous directory. Paths without : in them were current directory. Otherwise, a full path (starting with disk name) was expected, with components delimited by :. Ex: Macintosh HD:System Folder:Finder – derobert Jul 28 '11 at 22:32
  • @htorque yeah / is in / is in / ... See cd ///////////////////// ; pwd – dv3500ea Jul 29 '11 at 16:38
  • Though that's due to bash ignoring multiple slashes, e.g. cd /etc/////////init works too. – htorque Jul 29 '11 at 18:25
5

Those are hardlinks to self (.) and parent (..) directories. They are created when you crate a directory. They can never be deleted (without deleting directory pointed by them).

If you create a directory:

mkdir /tmp/foo

you can see, that there are actually 2 hardlink to /tmp/foo:

drwxr-xr-x 2 michal michal 4096 2011-08-07 18:40 /tmp/foo
           ^---- two hardlinks

first is from /tmp/ directory pointing to /tmp/foo, and the second is the '.' with in /tmp/foo/ pointing to it self.

3

Also, note that you can use ls -A (instead of ls -a) to list all files including hidden files, but excluding the . and .. directories.

Paddy Landau
  • 4,548
0

. currect folder

.. parent folder

RobinJ
  • 8,910