Hard Links and Soft Links
The inodes
An?inode?is something that contains the full description of a file or directory, including what it contains and its location on the hard drive. An?inode?does not have a fixed value. Indeed, it contains several data which have variable values which will change according to the use. It can be considered as the ID Card of a file or directory.
What is a Hard Link?
A hard link is a link that directly associates a name with a given file in an operating system, even if the file is renamed, a hard link will still be pointing to that file. This also means that the hard link you make to a file, will affect the file.
How to create a Hard Link
( ln test hardLink ) lets break this down
This creates another pointer to the exact same data.
Now I can read the file with: cat hardLink
When changes are made to one filename, the other reflects those changes. The permissions, link count, ownership, timestamps, and file content are the exact same. If the original file is deleted, the data still exists under the secondary hard link. The data is only removed from your drive when all links to the data have been removed.
But a Hard Link cannot be created for a folder or file in a different file system.
领英推荐
Now, what is a Soft (symbolic) Link?
A Soft Link it's a special file that points to an existing file. Same as Hard Links, any changes to the data in either file is reflected in the other. Basically are shortcuts to a file. Unlike a Hard Link, it does not changes the pointer when the file is renamed, if any changes are made to the file, the Soft Link will point to nothing.
How to create a Soft Link
( ln -s test softLink ) lets also break this down
Soft Links can point to another file or directory in any file system.
Hard Link or Soft Link?
It really depends on the situation, use it at your convenience
That's all, thanks for reading! :)