Lab 11: Create Hard and Soft Links
Objective Focus
- Understand and use essential tools
- Create hard and soft links
Official RHCSA EX200 Exam Objectives
Links in general
Links allow us to connect to a single point in the file system from other locations on the server. It is like building multiple roads to one city.
Inodes
In regard to linking, Inodes is how we can determine if a link is a hard link or a soft link. Inodes are an unique numerical value that is assigned to a file. These are used for hards links but are also used by the kernel for working with files.
$ stat /etc/File10
- the stat command will list the inode
$ ls -li
- ls will show current amount of links and the -i option will list the inode
Hard Links
Hard links refers to links between files that share multiple levels of metadata. It is like giving the file another name but with the same metadata.
Files with hard links share the same inode. This means if the original is deleted, the data will still be accessible through the new link.
Hard Links cannot leave outside its file system and it cannot be used to link to directories.
The reason for this is that, it references the inode. The inodes in ext4 is not the same in a XFS file system. We talk more about file systems later.
For example, your operating system might use XFS but the USB connected to it might use exFAT. Very different file systems for different purposes.
If we run the cat command on the linked files we get the same output.
$ ln file1 file1_hlink
Soft Links
Softs link do not share the same inode and act a “shortcut” to the original file.
If the original file is deleted then the soft link is useless. It will exist but go nowhere.
Softs links can link to files in other file systems because inodes are not used.
Softs links use the path for linking.
ls -il will show the soft link and point to the original file.
$ ln -s file1 /file_slink
Why links
Links are important because it allows access to files from different locations.
We can use them to utilize one file without making copies and we can edit the file once, in one location, the changes are updated through the links.
That’s all for this lab!