1. Understand and Use Essential Tools
πRed Hat Certified System Administrator (RHCSA β EX200)
1. What are Links in Linux?
In Linux, a link is like a shortcut or a pointer to another file. It allows you to access the same data from multiple places without duplicating the actual file.
There are two types of links:
- Hard Link
- Soft Link (Symbolic Link)
2. Hard Links
Definition
A hard link is an additional name for an existing file.
- Both the original file and the hard link point to the same data on disk.
- Deleting one does not delete the other because the data still exists.
- Hard links cannot cross different filesystems (i.e., they must be on the same disk/partition).
- Hard links cannot link to directories (only files).
How it Works
Think of a file as an inode (a data structure storing file data).
- The original file has an inode.
- A hard link points to the same inode.
- If you change the file through the hard link, the changes appear when accessing the original file.
Commands
Create a hard link:
ln original_file.txt hardlink_file.txt
Check the links:
ls -l
- The link count (second column in
ls -l) increases when you create a hard link.
Example:
echo "Hello RHCSA" > file1.txt
ln file1.txt file1_hardlink.txt
ls -li
Output:
12345 -rw-r--r-- 2 user user 13 Feb 19 11:00 file1.txt
12345 -rw-r--r-- 2 user user 13 Feb 19 11:00 file1_hardlink.txt
- Both files have the same inode number (
12345). - The
2indicates two links pointing to the same data.
3. Soft Links (Symbolic Links)
Definition
A soft link (or symbolic link) is like a pointer or shortcut to another file or directory.
- Soft links have their own inode, different from the original file.
- They store the path to the original file.
- If the original file is deleted, the soft link breaks and becomes a βdangling linkβ.
- Soft links can point to directories.
- Soft links can cross filesystems, unlike hard links.
Commands
Create a symbolic link:
ln -s original_file.txt softlink_file.txt
Check it:
ls -l
Example:
lrwxrwxrwx 1 user user 13 Feb 19 11:05 softlink_file.txt -> original_file.txt
lat the beginning of permissions indicates it is a link.- The arrow
->shows the file it points to.
Example Use Cases in IT
- Linking config files in
/etc/so multiple services can use the same config. - Pointing
/var/www/htmlto a different directory for a web server deployment.
4. Key Differences Between Hard and Soft Links
| Feature | Hard Link | Soft Link (Symbolic Link) |
|---|---|---|
| Points to | File’s inode | File path |
| Can point to directories? | No | Yes |
| Can cross filesystems? | No | Yes |
| Breaks if original file deleted? | No | Yes |
| Own inode? | No | Yes |
| Link type | Exact copy pointer | Shortcut pointer |
5. How to Check Links
1. Using ls -l
- Hard link: same inode number
- Soft link:
lin the first column and shows->to target
2. Using stat
stat file1.txt
stat file1_hardlink.txt
- Same inode for hard links
- Different inode for soft links
6. Common Exam Tasks You Might Be Tested On
- Create a hard link to a file and confirm it works.
- Create a soft link to a file or directory.
- Identify whether a file is a hard link or soft link.
- Understand the difference in behavior when the original file is deleted.
- Use links in real IT scenarios, like pointing multiple services to the same config file or organizing files efficiently.
7. Quick Tips for the Exam
- Hard link =
ln file1 file2 - Soft link =
ln -s file1 linkname ls -lishows inode numbers for hard links.ls -lshows the target of symbolic links.- Deleting a soft link only deletes the link, not the original file; deleting the original file breaks the link.
