Hard link vs Symbolic link
This blog post describing the differences and characteristics between Hard link and symbolic link in Linux.
What does link mean?
A file on a computer is a collection of data that has a specific physical location. Therefore, to access a file, we must know where it is physically stored. for them we require an inode. An inode contains the characteristics of a file, directory or any other object that the file system may contain. These inodes are not what we commonly see, what we usually do is give files or documents a name, and that is where the concept of a link comes in, because by naming we create a pointer to that inode or information from our file and that is the link.
A hard link is nothing more than a label or a new name associated with a file. It is a way of identifying the same content with different names. This link is not a separate copy of the previous file but a different name for the exact same content.
- Links have actual file content.
- Any change in the data of any of the files is reflected in the hard link
- Removing any link only reduces the number of links, but does not affect other links.
- We cannot create a hard link for a directory to avoid recursive loops.
- If the original file is deleted, the link will still show the contents of the file.
To create and see a hard link in Linux from the file fileale.txt to filenewname.txt, we execute:
- first with the ls command (list of files and directories) you can see I have a file fileale.txt
- now to create a hard link we use the ln command, like this:
$ ln [original file name] [hard link name]
3. Finally, in order to see that it was created, we use ls -l and as you can see in the image2 my original file and my hard link are underlined, the hard link has he same characteristics of the original file
We just saw that the hard links point to a file stored on our hard drive. In contrast, symbolic links point to the name of a file and later the file points to inode.
- Soft Link contains the original file path and not the content.
- Removing the symbolic link does not affect anything other than removing the original file, the link becomes a “dangling” link pointing to a non-existent file.
- A symbolic link can link to a directory.
- Link Across File Systems — If you want to link files across file systems, you can only use symbolic links / soft links.
To create and see a symbolic link in Linux from the file fileale.txt to filenewname.txt, we execute:
- first with the ls -l command (list of files and directories) you can see I have a file fileale.txt
- now to create a symbolic link we use the ln command, like this:
$ ln -s[original file name] [hard link name]
3. Finally, in order to see that it was created, we use ls -l and as you can see in the image3 my original file and my hard link are underlined, the symbolic one is pointed to the original file name.
As a conclusion we are going to see a comparative table with the main characteristics of the link types:
Soft and Hard links in Unix/Linux - GeeksforGeeks
A link in UNIX is a pointer to a file. Like pointers in any programming languages, links in UNIX are pointers pointing…