Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
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
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 1h 0m
Published
Clock icon Feb 12, 2019

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.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans