Linux Directories Introduction

What is a Directory

A directory is like as a folder like windows. Linux directory is a table which contains all its files Inode number and connect it to the file system.

Like example of :

# ls -ali new1   

See your terminal after run the command, command “ls -ali new1” displays all the files of directory new1.

Dot (.) and DotDot (..)

You can see notice there are two files with file name dot (.) and dotdot (.)

The dot (.) is a mapping to itself and the dotdot (..) is a mapping to the parent directory.

Hard Links

Creating Hard Links

Hard links for any file can be create with command ln. One extra hard link file will be create in the respective directory.

Now you have created a hard link for the file xyz in the directory new1.

Original file and hard linked file both contain the same Inode number and they have the same permissions and same owners.

Content will also be the same for both the files.

In short, both the files are equal now, but if original file will be remove then hard link file will not be affect.

Finding Hard Links

The linux hard link can be find with find command. It is help to specifying the Inode number. Inode number is always unique to its partition.

Like example of :

# find / -inum 662786 2> /dev/null  

See your terminal after run the command, we have found hard link files with command “find / -inum 662786 2> /dev/null” for the Inode number 662786.

Symbolic Links

Symbolic links are also call soft links.

ln -s command is used for soft link. That is doesn’t link to Inodes but create a name to mapping. It create its own Inode number.

Like example of :

# ln -s xyz symlink_to_xyz   

See your terminal after run the command, we have created a symbolic link for file xyz with command “ln -s xyz symlink_to_xyz”.

The symbolic link Inode is different from the original file Inode number. Target permissions are applied on the symlink file.

Hard links are limited to their own partition, but symbolic links can be link anywhere.

Removing Links

Linux rm command links can be remove.

See your terminal after run the command, directory link contains both hard link and soft link. The rm we have removed both the links.

If you understand this article then you can practice your own ability. Thank you.