- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud
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.
Lab Info
Table of Contents
-
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.txtFirst, let's try the gzip compression method. The following command will compress the junk.txt file using gzip:
gzip junk.txtNow, run the 'ls' command to view the size of the file:
ls -lhNotice 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.gzNext, perform the same steps, using the bzip2 compression method:
bzip2 junk.txtNote 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.bz2Once again, decompress the file to get the original back:
bunzip2 junk.txt.bz2Now we will try out a newer compression method, using 'xz':
xz junk.txtNote that this compression will take some time as well. Once the command completes, view your file's size:
ls -lhAnd finally, decompress the file:
unxz junk.txt.xz -
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.txtThen, make a new tarball using bzip2:
tar -cvjf bztar.tar.bz2 junk.txtLastly, use xz to make a tarball:
tar -cvJf xztar.tar.xz junk.txtRun the ls command again to compare the file sizes:
ls -lhNotice 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.
-
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 passwdUse the bzcat command to read the bzip2 compressed file:
bzcat passwd.tar.bz2Do the same for a gzipped tar file:
tar -cvzf passwd.tar.gz passwdAnd use the zcat command to read this compressed file:
zcat passwd.tar.gzAnd finally, create an xz tar file:
tar -cvJf passwd.tar.xz passwdAnd use the xzcat command to read its contents:
xzcat passwd.tar.xzWhen done, hand the server over to be graded.
About the author
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.