Understand the importance of . and .. in Linux

I wanted to share a small lesson that I've learned recently. Have you ever wondered what does . and .. refer to when you ls -l into a directory in Linux?

In this post, I will try to explain to you what people mean when they say . refers to the current directory and .. refers to parent directory (one level above).

In this case, I have created a directory called test for demonstration purposes that is empty for now.

[tux@server1 Documents]$ mkdir test

[tux@server1 Documents]$ ls -la test
total 0
drwxrwxr-x. 2 tux tux  6 Apr 23 21:12 .
drwxr-xr-x. 3 tux tux 18 Apr 23 21:12 ..

Notice -i option refers to the inode number that identifies one file from another.

image.png Observe the inode number (i.e. 1550977) on the left of both of the files. And, the number 2 in this case represents amount of inodes in this directory.

Important note:

  • Almost everything is a file in Linux
  • A directory is a special type of file in Linux
  • An inode represents the metadata of a file/directory.

Learn more about difference between hard links and symbolic links .

Did you know you can figure out the subdirectory count of a directory without going inside of the directory?

image.png The number 119 represents the total number of inodes and if you subtract by 2 (. and ..) then you will get 117 subdirectories inside it. Always remember to substract by 2.

Do let me know if it was helpful and please don't hesitate to share your constructive comments and criticism at Twitter: @hacback17