Soft and Hard links

joel silva
2 min readFeb 2, 2021

--

A link in UNIX is a pointer to a file. Like pointers in any programming languages, links in UNIX are pointers pointing to a file or a directory. Creating links is a kind of shortcuts to access a file. Links allow more than one file name to refer to the same file, elsewhere.

There are two types of links :

1.- Soft Link or Symbolic links

2.- Hard Links

These links behave differently when the source of the link (what is being linked to) is moved or removed. Symbolic links are not updated (they merely contain a string which is the pathname of its target); hard links always refer to the source, even if moved or removed.

1.-Hard Links

Hard links directly link two files in the same file system and for identification it uses file’s inode number. Hard links cannot be implemented on directories (since they point to inode). When “ln” command is utilized to generate a hard link, it creates another file on the command line which can be used to refer the original file. Both the original and generated file have the same inode and content; hence they will have the same permissions and the same owner.

2.-Soft link or Symbolic

Soft links are usually an alternative path (or an alias) for the original file; these are also referred to as symbolic links. It includes the name of the link’s “target file”, flag which specifies that it is a soft link. When a file is accessed the soft link redirects it to the target file through the path written in the subject of the soft link.

KEY DIFFERENCES

  1. A hard link is an additional name of the original file which refers inode to access the target file. In contrast, soft link is distinct to the original file and is an alias to original file but do not uses inode.
  2. When an original file gets deleted soft link becomes invalid whereas, a hard link is valid even if the target file is deleted.
  3. In Linux, the command used for the creation of hard link is “ln“. As against, the command used for a soft link is “ln -s“.
  4. Hard link has same inode number dissimilar to soft link, where target file and its soft link have distinct inode number.
  5. Hard links are restricted to its own partitions, but soft links can cover different file systems.
  6. The performance of hard link is better than soft link in some cases.
  7. Relative path and absolute path both are allowed in soft links. On the contrary, the relative path is not allowed in a hard link.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

joel silva
joel silva

No responses yet

Write a response