Photo by Chris Ried on Unsplash

The difference between a hard link and a symbolic link

The command ln is for creating a hard link or symbolic link, more details about this command will be explained below. There are two kinds of link: a hard link, and a symbolic link. How are they different? Here are some key differences:

  • A hard link cannot link across a different disk, while a symbolic link can
  • A hard link can be moved to a different directory, while a symbolic link cannot. Same concept applies when moving the original file too.
The very top row shows files that are visible to the user.

Hard link:

Referring from man ln: To create a hard link to a file from your current directory, the code will be ln originalFile linkName. The synopsis (command format) for creating both a hard link and symbolic link is as follows…

Symbolic Link:

We will be using the same example file test.js , and we want to create a symbolic link to it. Referring from man ln , the option -s is what allows ln to create a symbolic link instead of a hard link. So the code will be ln -s test.js symbolic_link_test.js .

Software Engineer living in Tokyo | Linux | Cats | https://github.com/kai-dg | https://haruspace.dev | https://ko-fi.com/harukai

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store