thelinuxvault blog

Quiz about Archiving and Compressing in Linux

Archiving and compressing files in Linux are essential skills for system administrators and power users alike. Archiving allows you to combine multiple files and directories into a single file, while compression reduces the size of files and archives, saving disk space and making data transfer faster. This blog post presents a quiz to test your knowledge of archiving and compressing in Linux, along with detailed explanations of the concepts and best practices.

2026-06

Table of Contents#

  1. Question 1: Basic Archiving with tar
  2. Question 2: Compression Formats
  3. Question 3: Compressing and Archiving in One Step
  4. Question 4: Extracting Archives
  5. Question 5: Best Practices for Archiving and Compression
  6. Answers and Explanations
  7. References

Question 1: Basic Archiving with tar#

What is the correct command to create a tar archive named myarchive.tar containing the files file1.txt, file2.txt, and the directory mydir? A. tar -cvf myarchive.tar file1.txt file2.txt mydir B. tar -xvf myarchive.tar file1.txt file2.txt mydir C. tar -zcvf myarchive.tar file1.txt file2.txt mydir D. tar -jcvf myarchive.tar file1.txt file2.txt mydir

Question 2: Compression Formats#

Which of the following compression formats is known for its high compression ratio but relatively slower compression speed? A. gzip (.gz) B. bzip2 (.bz2) C. xz (.xz) D. zip (.zip)

Question 3: Compressing and Archiving in One Step#

What command would you use to create a compressed tar archive named myarchive.tar.gz containing the files file1.txt and file2.txt? A. tar -cvf myarchive.tar.gz file1.txt file2.txt B. tar -zcvf myarchive.tar.gz file1.txt file2.txt C. tar -jcvf myarchive.tar.gz file1.txt file2.txt D. tar -xvf myarchive.tar.gz file1.txt file2.txt

Question 4: Extracting Archives#

How would you extract the contents of a myarchive.tar.bz2 archive to the current directory? A. tar -cvf myarchive.tar.bz2 B. tar -zxvf myarchive.tar.bz2 C. tar -jxvf myarchive.tar.bz2 D. tar -xvf myarchive.tar.bz2

Question 5: Best Practices for Archiving and Compression#

Which of the following is a best practice when archiving and compressing files in Linux? A. Always use the highest compression ratio available, regardless of the time it takes. B. Keep a backup of the original files before archiving and compressing. C. Use a single large archive for all files, regardless of their type or usage. D. Avoid compressing already compressed files, as it may increase the file size.

Answers and Explanations#

Answer 1: A#

  • Option A: tar -cvf myarchive.tar file1.txt file2.txt mydir is the correct command. The -c option creates a new archive, -v enables verbose mode (showing the files being added), and -f specifies the archive file name.
  • Option B: tar -xvf is used to extract an archive, not create one.
  • Option C: tar -zcvf is used to create a gzip - compressed tar archive. The question asks for a non - compressed tar archive.
  • Option D: tar -jcvf is used to create a bzip2 - compressed tar archive.

Answer 2: C#

  • Option A: gzip (*.gz) offers a good balance between compression ratio and speed. It is relatively fast and provides a decent compression ratio.
  • Option B: bzip2 (*.bz2) has a higher compression ratio than gzip but is slower.
  • Option C: xz (*.xz) is known for its extremely high compression ratio, but it has the slowest compression speed among the common Linux compression formats.
  • Option D: zip (*.zip) is more commonly used on Windows systems. While it can be used in Linux, its compression performance is generally not as good as the native Linux compression formats.

Answer 3: B#

  • Option A: tar -cvf creates a non - compressed tar archive. It will not compress the files with gzip.
  • Option B: tar -zcvf is the correct command. The -z option tells tar to use gzip for compression, -c creates a new archive, -v enables verbose mode, and -f specifies the archive file name.
  • Option C: tar -jcvf is used to create a bzip2 - compressed tar archive, not a gzip - compressed one.
  • Option D: tar -xvf is used to extract an archive, not create one.

Answer 4: C#

  • Option A: tar -cvf is used to create a tar archive, not extract one.
  • Option B: tar -zxvf is used to extract a gzip - compressed tar archive (*.tar.gz).
  • Option C: tar -jxvf is the correct command. The -j option indicates that the archive is compressed with bzip2, -x extracts the archive, -v enables verbose mode, and -f specifies the archive file name.
  • Option D: tar -xvf is used to extract a non - compressed tar archive.

Answer 5: B and D#

  • Option A: Using the highest compression ratio available can be time - consuming. It is better to balance the compression ratio with the time required, especially for large files or when time is a constraint.
  • Option B: Keeping a backup of the original files is a best practice. Archiving and compression involve modifying the original data, and having a backup ensures that you can recover the data in case of any issues.
  • Option C: Creating a single large archive for all files can make it difficult to manage and extract specific files. It is better to group files logically into separate archives based on their type, usage, or time of creation.
  • Option D: Compressing already compressed files (such as JPEG or MP3 files) can actually increase the file size due to the overhead of the compression algorithm. So, it is best to avoid compressing them.

References#