What is Soft Links and Hard Links in Linux File System

This short post explains what links are and the difference between symbolic (soft) and hard links. A link is a mechanism that allows several filenames to refer to a single file on disk. There are two kinds of links:1. hard links.
2. symbolic (soft) links.

Hard Links

– A hard link associates two (or more) filenames with an inode.
– Hard links all share the same disk data blocks while functioning as independent directory entries.
– Hard links may not span disk partitions, since inode numbers are only unique within a given device.

Symbolic Links

– A symbolic link is a special file type which points to another file.
– The contents of this special file is the name of the file that it points to.
– Symbolic links are created by the “ln -s“” command.
– Once a file which is pointed to by a symbolic link is deleted, the link still points to it, leaving a hanging link.
– You can use the find command to locate symbolic links:

# find ./* -type l -ls

Examples

1. Consider a file ‘example’ to which there is a hard link ‘hlink’ and a symbolic link ‘slink’. Check the contents of the directory for the file ‘example’: