So, if you are reading this blog then you are confused with the fact that each of the directory in your linux/unix box contains a"." and ".." , what does this basically means?
Well the answer is really simple, You just need to use a little bit of logic. Let me demonstrate you with an example.
Scenario 1
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?
Answer
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.
Scenario 2
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)
Answer
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
and double dot ".." means one step back i.e. the parent directory, that is the only directory where that directory is referenced from
You can see the size difference between "." and".." accordingly below
I hope the article was useful.
Well the answer is really simple, You just need to use a little bit of logic. Let me demonstrate you with an example.
Scenario 1
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?
Answer
# 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.
Scenario 2
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)
Answer
# 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.
What is . and .. in Unix/Linux ?
Reviewed by Deepak Prasad
on
Wednesday, December 25, 2013
Rating:
Easy and understandable explanation using Inodes. Thank you
ReplyDeletecool
ReplyDelete