There are two types of links in Linux systems, hard links and symbolic links. A link provides connectivity between the filename and the actual data byte in the disk space. Hence, multiple links can be created for the same data.
Hard Links
It links more than one filename with the same Inode and it represents the physical location of a file. When a hard link is created for a file, it directly points to the Inode of the original file in the disk space, which means no new Inode is created. Directories are not created using hard links and they cannot cross filesystem boundaries. When the source file is removed or moved, then hard links are not affected.
Creating Hard Links
Hard links for any file can be created with the command ln. One extra hard link file will be created in the respective directory. The original file and hard-linked file both contain the same Inode number and hence, they have the same permissions and the same owners. Content will also be the same for both files. In short, both files are equal now, but if the original file will be removed then the hard link file will not be affected.
Finding Hard Links
A hard link can be found with the find command by specifying the Inode number. Inode number is always unique to its partition.
find / -inum 662786 2> /dev/null
Soft Links / Symbolic Links
It represents a virtual or abstract location of the file. It is just like the shortcuts created in Windows. A soft link doesn't contain any information or content of the linked file, instead, it has a pointer to the location of the linked file. In other words, a new file is created with a new Inode, having a pointer to the Inode location of the original file. It is used to create links between directories and can cross filesystem boundaries. When the source file is removed or moved, then soft links are not updated.
Creating Soft Links
Symbolic links are also called soft links. The command ln -s
is used to create a soft link. It doesn't link to Inodes but creates a name for mapping. It creates its own Inode number.
ln -s xyz symlink_to_xyz
Removing Links
With rm
command links can be removed.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.