Skip to main content

Using Absolute and Relative Paths

Hands-On Lab

 

Photo of Michael Christian

Michael Christian

Course Development Director in Content

Length

00:15:00

Difficulty

Beginner

In this hands-on lab, we will practice using absolute and relative paths. Understanding the difference between absolute and relative paths is a critical component to working with files and directories in Linux.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Using Absolute and Relative Paths

Introduction

In this hands-on lab, we will practice using absolute and relative paths.

Connecting to the Lab

  1. Open your terminal application, and run the following command (remember to replace <PUBLIC_IP> with the public IP you were provided on the lab instructions page):
    ssh cloud_user@<PUBLIC_IP>
  2. Enter yes at the prompt.
  3. Enter your cloud_user password at the prompt.

Use Absolute Paths to Move the File

  1. Determine the current working directory.
    pwd
  2. Run the following command:
    cat /home/cloud_user/Practice/Test/free > /home/cloud_user/value.txt
  3. List the contents of the current working directory.
    ls
  4. List the contents of the value.txt file we just created.
    cat value.txt

Use Relative Paths to Move the File

  1. Change to the /usr/share directory.
    cd /usr/share/
  2. Run the following command:
    cat ../../home/cloud_user/Practice/Test/sys/fs/xfs/stats/stats >> ../../home/cloud_user/value.txt
  3. List the details for the value.txt file.
    ls -l ~/value.txt
  4. Change to the home directory.
    cd
  5. List the contents of the value.txt file.
    cat value.txt

Conclusion

Congratulations, you've successfully completed this hands-on lab!