Create and Extract Tar Archives

LinuxLinuxBeginner
Practice Now

Introduction

In this challenge, you will create compressed tar archives of the /home directory using both gzip and bzip2 compression methods, and then extract them. This skill is essential for system administrators who need to efficiently backup and transfer large amounts of data.

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/CompressionandArchivingGroup(["`Compression and Archiving`"]) linux/CompressionandArchivingGroup -.-> linux/tar("`Archiving`") linux/CompressionandArchivingGroup -.-> linux/zip("`Compressing`") linux/CompressionandArchivingGroup -.-> linux/gzip("`Gzip`") subgraph Lab Skills linux/tar -.-> lab-389290{{"`Create and Extract Tar Archives`"}} linux/zip -.-> lab-389290{{"`Create and Extract Tar Archives`"}} linux/gzip -.-> lab-389290{{"`Create and Extract Tar Archives`"}} end

Create and Extract Compressed tar Archives

Tasks

  1. Create gzip and bzip2 compressed tar archives of the /home directory
  2. List the contents of both archives
  3. Extract both archives

Requirements

  • Perform all operations in the /home/labex directory
  • Create the following archives:
    • Gzip-compressed: /home/labex/home.tar.gz
    • Bzip2-compressed: /home/labex/home.tar.bz2
  • List the contents of both archives in /home/labex
  • Extract both archives to /home/labex/extracted
  • Use the tar command with appropriate options for all operations

Example

After creating the gzip-compressed archive, listing its contents might look like this:

$ tar -tvf /home/labex/home.tar.gz
drwxr-xr-x root/root         0 2023-08-28 10:00 home/
drwx------ labex/labex       0 2023-08-28 10:00 home/labex/
-rw-r--r-- labex/labex     220 2023-08-28 10:00 home/labex/.bash_logout
-rw-r--r-- labex/labex    3771 2023-08-28 10:00 home/labex/.bashrc
-rw-r--r-- labex/labex     807 2023-08-28 10:00 home/labex/.profile

Summary

In this challenge, you learned how to create compressed tar archives using both gzip and bzip2 compression methods, as well as how to list their contents and extract them. You practiced using the tar command with various options to perform these tasks in specific directories, enhancing your command-line skills and understanding of file compression techniques in Linux systems.

Other Linux Tutorials you may like