Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Google Cloud Platform icon
Labs

Working with Compressed Files in Linux

Each candidate for the LPIC-1 or CompTIA Linux exam needs to understand how to work with various types of compressed files, or "tarballs" as they are commonly known. We will practice with various compression tools, and compare the differences between them.

Google Cloud Platform icon
Lab platform
Lab Info
Level
Beginner
Last updated
May 29, 2025
Duration
1h 0m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Try out different compression methods

    Note: Please give the lab an extra minute or so before connecting via ssh to allow the lab to fully provision.

    Take a look at the original size of your junk.txt file, and make note of it:

    ls -lh junk.txt
    

    First, let's try the gzip compression method. The following command will compress the junk.txt file using gzip:

    gzip junk.txt
    

    Now, run the 'ls' command to view the size of the file:

    ls -lh
    

    Notice that the gzip command replaced the original file with a compressed version of it. The other compression commands we will use will do the same. Take note of the smaller size of the file. Then, decompress the gzip file to get the original junk file back:

    gunzip junk.txt.gz
    

    Next, perform the same steps, using the bzip2 compression method:

    bzip2 junk.txt
    

    Note that this compression method will take slightly longer than the previous. Make a note of the bzip2 file's size (typically, these file sizes are smaller than gzip compressed files):

    ls -lh junk.txt.bz2
    

    Once again, decompress the file to get the original back:

    bunzip2 junk.txt.bz2
    

    Now we will try out a newer compression method, using 'xz':

    xz junk.txt
    

    Note that this compression will take some time as well. Once the command completes, view your file's size:

    ls -lh
    

    And finally, decompress the file:

    unxz junk.txt.xz
    
  2. Challenge

    Create tar files using the different compression methods.

    This next set of tasks will focus on working with tar files. First, use the gzip compression method to make a tarball:

    tar -cvzf gztar.tar.gz junk.txt
    

    Then, make a new tarball using bzip2:

    tar -cvjf bztar.tar.bz2 junk.txt
    

    Lastly, use xz to make a tarball:

    tar -cvJf xztar.tar.xz junk.txt
    

    Run the ls command again to compare the file sizes:

    ls -lh
    

    Notice that creating tar files did not replace the original junk.txt file. Note also how close in size the xz and bzip2 files are to each other.

  3. Challenge

    Practice reading compressed text files.

    The final group of tasks will demonstrate how to read compressed files, without decompressing them on your disk. First, copy over the /etc/passwd file to your home directory:

    cp /etc/passwd .
    

    Now, compress the file using bzip2 into a tarball:

    tar -cvjf passwd.tar.bz2 passwd
    

    Use the bzcat command to read the bzip2 compressed file:

    bzcat passwd.tar.bz2
    

    Do the same for a gzipped tar file:

    tar -cvzf passwd.tar.gz passwd
    

    And use the zcat command to read this compressed file:

    zcat passwd.tar.gz
    

    And finally, create an xz tar file:

    tar -cvJf passwd.tar.xz passwd
    

    And use the xzcat command to read its contents:

    xzcat passwd.tar.xz
    

    When done, hand the server over to be graded.

About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

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.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight