Soft Link Vs. Hard link
Juan Sebastian Gonzalez
Software Developer | Full-Stack Developer | Javascript | React | Nextjs | Redux | Node.js | Python | Django | DRF | Nestjs | Fast Api | Docker | MYSQL | MONGO | ARANGODB
Understanding the difference between a hard link and a symbolic link requires knowledge of how computers store and access data. A computer's hard drive is composed of switches that represent 1's and 0's, and files are stored as a series of these switches. In order to access a file, the computer must know the physical location of the data within the switch series.
To facilitate this, computers use a data structure called an inode, which contains metadata and a pointer to the data's physical location. Filenames on a computer are actually pointers to inodes, and directories serve as a way to organize these filenames. Inodes act as intermediaries between the name of the file and its actual location on the hard drive.
This is where hard links and symbolic links come into play. For example, if you create a file called "file1", the computer creates a link from the filename to its corresponding inode, which in turn points to the physical storage location of the file. If you create a hard link called "h-link", it points to the same inode that "file1" does. However, if you create a symbolic link called "s-link", it points to the filename "file1" rather than to the inode.
In summary, hard links and symbolic links are different ways of linking filenames to their corresponding data on a computer's hard drive. Hard links point directly to the inode, while symbolic links point to the filename itself. Understanding the differences between these types of links is crucial for effective file management on a computer system.
Look at the image below.
In Linux:
领英推荐
which one to use?
There are advantages and disadvantages to both approaches.
When you move or delete the original file named "file1," the "h-link" points to the previously assigned inode, preserving the relevant data. However, the "f-link" becomes obsolete because it can no longer locate the original file name.
On the other hand, creating an "f-link" on a second file system is straightforward - you can simply create a link to a file name. However, this is not possible with "h-link" since it cannot locate the inode if you are in a different file system.
In summary, both "h-link" and "f-link" have their benefits and limitations, depending on the situation at hand.
Click for more information about.
.