Lab 10: Archive Compress Unpack and Uncompress Files

Objective Focus
Understand and use essential tools
Archive, compress, unpack, and uncompress files using tar, gzip, and bzip

Official RHCSA EX200 Exam Objectives

Why do we need compression

There are many files on a computer that are created automatically. These can become very large in size. This takes up valuable space on drive with finite space.

Log files can also become large and take up space. We deal with this by using compression and archiving.

Compression and archiving allow use to manage large files and directories.

Compression is used to conserve space. Archiving allows us to combine multiple files and directories into one file.

Compression

 $ gzip largefile.txt 
 $ bzip2 largefile.txt 

Decompress

 $ gunzip largefile.txt.gz  
 $ bzip2 largefile.txt.bz2 

Archiving

For archiving, we use tar aka tape archive.

 $ tar -cvf etc.tar /etc  
The ask

Our goal will, usually, be to take many directories and make them into a single file using tar and compress at the same time.

 $ tar -czvf etc.tar.gz /etc  
-z option is to compress using gzip
 $ tar -cjvf etc.tar.bz2 /etc  
-j option is to compress using bzip2

We will check the sizes after to ensure the compression worked using du.

 $ du -sh /etc 
Extracting
 $ tar -xvf /etc.tar.gz or $ tar -cjvf etc.tar.bz2
This extracts the directorie(s) or file into the current directory.
 $ tar -xvf /etc.tar.gz -C /home/learner 
This allows the extraction to another directory

Compression and archiving really plays a part in keeping systems up and ensuring free space is always available. In my professional work, I have see servers run out of disk space due to logs files explding in size without anyone knowing.

Then, scripts are created with compression and archiving commands scheduled to run on the server to ensure it does not happen again.

So, thats it for this lab!!