Working with Links in Linux

Get Started
30 minutes
  • 5 Learning Objectives

About this Hands-on Lab

Understanding how soft and hard links work within Linux is another important skill for a system administrator. This learning activity will help you practice creating these two types of links on a file system, and explore the differences between the two.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a Symbolic (soft) Link

Using the ln command, create a symbolic link from the file /etc/redhat-release to a new link file named release in the cloud_user’s home directory. Using the ls command, verify that the link is valid. Use the cat command on the /home/cloud_user/release file to verify its contents.

Can be completed with:

ln -s /etc/redhat-release release
ls -al

cat /etc/redhat-release
Check the Inode Numbers for the Link

Using the ls command, first look at the inode number for the /home/cloud_user/release link and then check the inode number for /etc/redhat-release. They should be different, as the symbolic link is just a new file system entry that references the original file.

Viewing the inodes can be done via:

ls -i release
ls -i /etc/redhat-release
Create a Hard Link

Create a directory called docs in your home directory. Copy the /etc/services file into this new docs directory. Using the ln command again, create a hard link from /home/cloud_user/docs/services to a link file named /home/cloud_user/services. Use the ls command to verify the link’s inode number, and the inode number for the original /etc/services file.

The commands to accomplish this task are:

mkdir docs
cp /etc/services docs/
ln docs/services services
ls -al (to show valid)

ls -i services
ls -i docs/services
(same inode)
Attempt to Create a Hard Link Across File Systems

Using the ln command, attempt to make a hard link from /home/cloud_user/docs/services to /opt/services (you will have write permissions to this location). Why does this not work?

To see the behavior of this task, try the following:

(/dev/xvda /)
(/dev/xvdg1 /opt)

ln docs/services /opt/services
Attempt to Create a Symbolic Link Across File Systems

Once more using the ln command, attempt to create a soft link from /etc/redhat-release to /opt/release. Why does this work, but creating a hard link fails? Turn the system over for grading when complete.

Creating the soft link should succeed, even across filesystems, like so:

   sudo  ln -s /etc/redhat-release /opt/release
ls -i (new inode vs. same inode on hard link)

Additional Resources

Make sure to review the man page for the ln command to know how to make a symbolic and hard link for files.

You have been asked by your development team to help them structure their filesystem with links to various files. They would like the following items created on the system for their use:

  • Create a symbolic link, /etc/redhat-release, to a file in the cloud_user's home directory called release.
  • View the inodes to verify each file was created correctly.
  • Create a directory called docs in the cloud_user home directory and copy the /etc/services files here.
  • Link this new docs/services file to a file called services in the cloud_user home directory
  • Display the inodes to verify they are the same
  • Attempt to create a hard link from docs/services to /opt/services and note whether the link recognizes that each location is on a different filesystem.
  • Create a symbolic link from /etc/redhat-release to /opt/release and view the inodes to see if symbolic links can be created across those same filesystems.
What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?