Linux Hard Links versus Soft Links Explained

Understanding the terminology is one of the most important aspects of learning a new technology. Linux is no exception. The OS is full of terms and phrases. Learning to use it can be difficult because some words are borrowed from other systems. Others only apply to Linux. Linux and Unix-like OSs have hard links and soft links. Understanding them can help you navigate through the filesystems of Linux. Our Linux training module covers soft links, hard links, as well as other topics.
What are Soft Links?
Quick definition: A soft link (also known as a symbolic or a symbolic file in Linux) is a special type of file that points to a different file. It could be thought of as a shortcut in Windows vocabulary. Soft links can point to entire directories and link to files on remote computers because the connection is logical. This is impossible with hard links.
What are hard links?
Quick definition: A hard link in Linux is the equivalent of a file stored on the hard drive. It actually refers to or points to a specific spot on the hard drive. A hard link is a mirror of the original file. A hard link is different from a soft one in that it doesn’t delete the original file, but renders a soft hyperlink inoperable.
An Overview of Hard and Soft Links [VIDEO]
Shawn Powers explains the difference between soft (or symbolic), links on a Linux OS 10 operating platform in this video. These are two ways files can be referenced on a hard disk. The former points to the file and the latter to the name of the file.
Learn how to become a security expert with SPOTO’s Cybersecurity Training
Start training
What are the differences between hard and soft links?
Linux and OS10 use terms such as hard links and soft links. Although both soft and hard links point at files, there is a key difference. It all comes down to what they refer to: hard links refer directly to the data, while soft links refer to the path to that data.
To understand the difference between a Hard Link and a Soft Link, we need to zoom in as deep as possible on a hard drive. In Linux systems, the data structure responsible for storing information is called an Inode. A hard link is a file that is its own. It refers to or points to the exact location on the hard drive where the Inode stores data. Soft links are not separate files. They point to the name of the original file and not to a specific spot on the hard disk.
How do hard links work?
Imagine a hard drive at the Inode level. This will allow you to visualize the data that each file represents. If you think hard enough, you will be able to see how much space it takes up on your hard drive. Now, imagine a file (let’s call it File 1) that points to the exact location on the hard disk where the data is stored. You can access the data by opening File 1. You can also make changes to the data on your hard drive.
Now, imagine that you create a hardlink to File 1. It’s a hard-link, so it’s a new file. We’ll call it File 2. However, File 2 will contain the same data as File 1. It’s a hardlink, so it points to the exact same place on the hard drive.
A hard link effectively gives you two separate files that behave as if they were different files. It’s better to not think of a hard-link as a copy. There’s an exception to this rule: File 1 will be modified, but File 2 will be automatically edited. This is because they are two separate files but point to the exact same place on the hard drive.
Both files will change if you go to the Inode level to make changes to the data — the spot that File 1 and 2 point to — They are separate files with different names and located in different places, even though they have different locations.

Related Posts