Well the answer is really simple, You just need to use a little bit of logic. Let me demonstrate you with an example.
You need to go one step back of the current directory where you are. For eg. you are inside /home/deepak and you want to go to /home so what is the command you would run?
# cd ..
Now does that 2 dots used after cd makes any sense? I think you must have got my point and the usage of double dot in each directory.
Try to find a file with name test inside the current directory and all directories inside the current directory. For eg. Find test file inside /home/deepak( which is your present working directory)
# find . -name test -type f
Now as you can see I have used a single dot "." to tell my system to only look in my current directory.
So basically single dot "." means current directory which actually is a hardlink to its containing directory.
You can verify the same using the below command
[deepak@server work]$ ls -di . "$PWD" 66232 . 66232 /home/deepak/work returns the same inode no.
and double dot ".." means one step back i.e. the parent directory, that is the only directory where that directory is referenced from
[deepak@server work]$ ls -di .. /home/deepak/ 22 .. 22 /opt/fti/
You can see the size difference between "." and".." accordingly below
[deepak@server work]$ ls -al total 1592 drwxrws--x 4 deepak deepak 2048 Nov 13 02:22 . drwxrws--x 23 deepak deepak 3864 Aug 22 09:57 ..
I hope the article was useful.
5 thoughts on “What is . and .. in Unix/Linux ?”
Easy and understandable explanation using Inodes. Thank you
then why does the root directory has . . when it is the top most directory??
Why are . and .. listed as directories if they are links.(supposedly)?
root@jackinthebox:/# ls -la
drwxr-xr-x 23 root root 4096 2014-02-17 16:36 .
drwxr-xr-x 23 root root 4096 2014-02-17 16:36 ..