LPI E - Exam Review 3.3 - tar

File Compression and Archiving

A Journey Through Tar and Gzip

navigate: 3.2 << -- >> 3.4

Review of Concepts

By understanding the principles of compression, archiving, and file management, one can navigate the realm of data optimization and storage with ease, harnessing the power of compression tools to enhance efficiency and manage data effectively.


 
Riddle 1
I am a widely used archiving tool on Linux systems. What am I?

A) Tar
B) Zip
C) Gzip
D) Xz

Riddle 2
What does "tar" stand for?

A) Tape archive
B) Text and archive
C) Tarball archive
D) Terminal archiving

Riddle 3
Which option is used to create a new archive file with tar?

A) c
B) t
C) u
D) v

Riddle 4
How can you view the contents of a tar ball?

A) t option
B) v option
C) u option
D) x option

Riddle 5
Which option can be used with tar to output the names of files it operates on?

A) v option
B) c option
C) u option
D) x option

Riddle 6
Which compression algorithm is represented by the option "z" in tar?

A) Bzip2
B) Gzip
C) Xz
D) Lzma

Riddle 7
What should you do when creating compressed .tar archives to indicate the compression algorithm used?

A) Add a second file extension denoting the algorithm
B) Include a special header in the archive
C) Specify the compression algorithm during extraction
D) Rename the archive with the compression algorithm's name

Riddle 8
Which option allows adding files to already existing uncompressed tar archives?

A) u
B) c
C) v
D) x

Riddle 9
What happens if you attempt to add files to a compressed tar archive?

A) The files are added successfully
B) An error occurs
C) The compression algorithm is automatically applied to the new files
D) The existing files in the archive are overwritten

Riddle 10
Which archiving tool is commonly bundled with compression tools on Windows systems?

A) Zip
B) Tar
C) Gzip
D) Xz

Answers

Answer to 1:

Answer: A) Tar

Explanation: The correct answer is Tar. The tar program is the most widely used archiving tool on Linux systems. It is often used to create tar balls, which are archive files created for bundling files and directories. Tar is commonly used for applications distributed as source code.

Answer to 2:

Answer: A) Tape archive
Explanation: The correct answer is A) Tape archive. The name "tar" is an abbreviation for "tape archive." This reflects its origins in the early days of computing when data was often stored on magnetic tape drives.

Answer to 3:

Answer: A) c
Explanation: The option "c" is used with tar to create a new archive file. This option is followed by the name of the file to create, specified with the "f" option.

Answer to 4:

Answer: A) t option
Explanation: To view the contents of a tar ball, you can use the "t" option with tar. This option lists the files and directories contained within the archive.

Answer to 5:

Answer: A) v option
Explanation: The "v" option can be used with tar to output the names of files it operates on. This option provides verbose output and can be helpful to track the files being processed.

Answer to 6:

Answer: B) Gzip
Explanation: The option "z" in tar represents the Gzip compression algorithm. Gzip is commonly used for compression and decompression of tar archives.

Answer to 7:

Answer: A) Add a second file extension denoting the algorithm
Explanation: When creating compressed .tar archives, it is recommended to add a second file extension denoting the compression algorithm used. For example, use .gz for Gzip, .xz for Xz, or .bz for Bzip2. This helps identify the compression algorithm used for the archive.

Answer to 8:

Answer: A) u
Explanation: The option "u" in tar allows adding files to already existing uncompressed tar archives. This option is used to update the contents of an archive with new files or directories.

Answer to 9:

Answer: B) An error occurs
Explanation: If you attempt to add files to a compressed tar archive, you will encounter an error. Adding files to a compressed archive is not supported, and it will result in an error message.

Answer to 10:

Answer: A) Zip
Explanation: On Windows systems, the archiving tool commonly bundled with compression tools is Zip. Zip files are widely used for archiving and compressing files on Windows platforms.

 

The Story

A Meeting with the Wise Dragon

In this treacherous domain, the adventurer encounters a wise dragon well-versed in the art of file compression and archiving. The dragon poses challenges related to the utilization of command line tools such as tar and gzip. Through understanding the intricacies of creating, extracting, and managing compressed archives, the adventurer learns the power of optimizing storage and transferring large amounts of data with ease.

Embracing the Intricacies of Tar and Compression

The tar program is probably the most widely used archiving tool on Linux systems. In case you are wondering why it is named how it is, it is an abbreviation for "tape archive". Files created with tar are often called tar balls. It is very common for applications distributed as source code to be in tar balls.

Creating and Exploring Archives with Tar

Let's start off by creating an archive of the files used for compression. The 'c' option instructs tar to create a new archive file, and the 'f' option is the name of the file to create. The argument immediately following the options is always going to be the name of the file to work on. The rest of the arguments are the paths to any files or directories you wish to add to, list, or extract from the file. In the example, we are adding the directory "compression" and all of its contents to the archive.

To view the contents of a tar ball, use the 't' option of tar. Notice how the options are preceded with '-'. Unlike most programs, with tar, the '-' isn't required when specifying options, although it doesn't cause any harm if it is used.

Unveiling the Secrets of Compression

Compression works by replacing repetitive patterns in data. Suppose you have a novel. Some words are extremely common but have multiple characters, such as the word "the". You could reduce the size of the novel significantly if you were to replace these common multi-character words and patterns with single character replacements. Data compression algorithms are similar to this but more complex.

Compression comes in two varieties, lossless and lossy. Things compressed with a lossless algorithm can be decompressed back into their original form. Data compressed with a lossy algorithm cannot be recovered. Lossy algorithms are often used for images, video, and audio where the quality loss is imperceptible to humans, irrelevant to the context, or the loss is worth the saved space or network throughput.

Adding Files and Unleashing the Power of Compression

The tar program can also manage compression and decompression of archives on the fly. Tar does so by calling one of the compression tools discussed earlier in this section. It is as simple as adding the option appropriate to the compression algorithm. The most commonly used ones are 'j', 'J', and 'z' for bzip2, xz, and gzip, respectively. Below are examples using the aforementioned algorithms.

Notice how in the example the .tar files have different sizes. This shows that they were successfully compressed. If you create compressed .tar archives, you should always add a second file extension denoting the algorithm you used. They are .xz, .bz, and .gz for xz, bzip2, and gzip, respectively. Sometimes shortened extensions such as .tgz are used.

The Dragon's Wisdom and Cautionary Notes

It is possible to add files to already existing uncompressed tar archives. Use the 'u' option to do this. If you attempt to add to a compressed archive, you will get an error.

Stand-alone compression tools aren't typically available on Windows systems. Windows archiving and compression tools are usually bundled together. Keep this in mind if you have Linux and Windows systems that need to share files.

Linux systems also have tools for handling .zip files commonly used on Windows systems. They are called zip and unzip. These tools are not installed by default on all systems, so if you need to use them, you may have to install them. Fortunately, they are typically found in distributions' package repositories.

As the adventurer delves deeper into the world of file compression and archiving, they gain valuable insights from the wise dragon. With newfound knowledge and skills, they are ready to face the challenges that lie ahead and harness the power of optimizing storage and transferring large amounts of data with ease.

Comments

Popular posts from this blog

Why Certifications Methods?

LPI E - ALL K.D.

CCNP 03 - WANS