Implement Hard Links in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this challenge, you will explore the concept of hard links in a Linux file system. You'll create hard links and modify file content, observing how these actions affect file attributes.

Environment

LabEx uses Red Hat Universal Base Image 9 (UBI9) to simulate the exam environment. It may not be identical to the actual RHCSA exam environment, but it provides a good representation of the tasks you'll encounter.

There are two users in the environment:

  • labex: A standard user with sudo privileges, password: labex.
  • root: The system administrator, password: redhat.

The challenge features real exam questions, along with explanations, requirements, and automated verification scripts to help you confirm task completion. It effectively simulates the knowledge areas covered in the RHCSA exam.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux/BasicFileOperationsGroup -.-> linux/cat("`File Concatenating`") linux/BasicFileOperationsGroup -.-> linux/ls("`Content Listing`") linux/BasicFileOperationsGroup -.-> linux/ln("`Link Creating`") subgraph Lab Skills linux/cat -.-> lab-389291{{"`Implement Hard Links in Linux`"}} linux/ls -.-> lab-389291{{"`Implement Hard Links in Linux`"}} linux/ln -.-> lab-389291{{"`Implement Hard Links in Linux`"}} end

Tasks

  1. Create an empty file named hard1
  2. Create two hard links to hard1: hard2 and hard3
  3. Add content to hard2

Requirements

  • All files must be created in the /home/labex directory
  • Create hard1 using the touch command
  • Create hard2 and hard3 using the ln command
  • Add the content "Redhat" to /home/labex/hard2 using the echo command
  • Use ls -li to display file attributes of all three files

Example

After completing the tasks, you should see output similar to this:

$ ls -li /home/labex/hard1 /home/labex/hard2 /home/labex/hard3
1234567 -rw-r--r-- 3 labex labex 7 Aug 28 10:00 /home/labex/hard1
1234567 -rw-r--r-- 3 labex labex 7 Aug 28 10:00 /home/labex/hard2
1234567 -rw-r--r-- 3 labex labex 7 Aug 28 10:00 /home/labex/hard3

The number at the beginning is the inode number, which will be the same for all hard links to the same file. Note that the link count is 3 for all files.

Summary

In this challenge, you explored hard links in a Linux file system. You created multiple hard links to the same file, observed how they share the same inode number, and how modifying one link affects all others. This exercise demonstrated the relationship between inodes, hard links, and file content in a Linux file system. Understanding these concepts is crucial for effective file management and storage in Linux environments, especially when dealing with file systems, backups, and data organization.

Other Linux Tutorials you may like