What is the difference between a soft link and a hard link?

Andres Condezo Monge
2 min readFeb 2, 2021
Hard and soft links

What is Soft link (symbolic link) in Linux?

A symbolic link, also termed a soft link, is a special kind of file that points to another file, much like a shortcut in Windows or a Macintosh alias. Unlike a hard link, a symbolic link does not contain the data in the target file. It simply points to another entry somewhere in the file system.

Creating Soft Link

The generic syntax for creating a soft link is as follows:

$ ln -s TARGET LINK_NAME
  • -s: Option to create symbolic links.
  • TARGET: Name of the existing file to which we will create the soft link.
  • LINK_NAME: Name of the soft link.

Let’s see an example:

$ ln -s test.txt my-softlink-to-test.txt

What is Hard link in Linux?

A hard link is a file that points to the same inode, as another file. In case you delete one file, it removes one link to the inode.

Creating Hard Link

The generic syntax for creating a hard link is as follows:

$ ln TARGET LINK_NAME
  • TARGET: Name of the existing file to which we will create the hard link.
  • LINK_NAME: Name of the hard link.

Let’s see an example:

$ ln test.txt my-hardlink-to-test.txt

What is the difference between a soft link and a hard link?

Soft link:

  • Can cross the file system,
  • Allows you to link between directories,
  • Has different inode number and file permissions than original file,
  • Permissions will not be updated,
  • Has only the path of the original file, not the contents.

Hard link:

  • Can’t cross the file system boundaries (i.e. A hardlink can only work on the same filesystem),
  • Can’t link directories,
  • Has the same inode number and permissions of original file,
  • Permissions will be updated if we change the permissions of source file,
  • Has the actual contents of original file, so that you still can view the contents, even if the original file moved or removed.

--

--