Demystifying the Differences Between Soft Links and Hard Links
Khaled Mustafa
Embedded Systems Educator | Master of Science in Mathematics and Computer Science
I wanted to upload my dot files to a GitHub repository, but they were spread across multiple directories. The solution was to create a link to these files in the Git repository, ensuring that any edits to the main configuration file would be reflected in the linked file.
There are two distinct types of links:
1. Symlink (Symbolic Links), also known as Soft Links:
These links point to the file itself and do not reference memory addresses. When you examine a symlink file, you'll only find the path to the linked file. This means that if you were to copy it to a different machine, it would become non-functional.
2. Hard Links:
A hard link is a file that points to the same memory address as the original file. You could think of it as an exact copy, and any changes made in either file will be mirrored in the other.
Thus, for our use case, Hard Links is to win.
How to create a Hard Link?
This is simply done using the ln command without adding any options to it.
For example, ln ./TextFile.txt ./HardLinkFile.txt
In case of hard links, if you deleted the original file, the hard link file won't be affected, this is the contrary of soft link files, they will be nonfunctional.