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
. ..
.
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.
::
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
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.
Also, note that you can use ls -A
(instead of ls -a
) to list all files including hidden files, but excluding the .
and ..
directories.
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.