010-160 Archiving and Compression 4 — Questions and Answers
Question 1: Which compression tool generally achieves the highest compression ratio among gzip, bzip2, and xz?
- xz (Correct answer)
- gzip
- bzip2
- They all achieve equal compression
Correct answer: xz
xz typically achieves the best compression ratio of the three but is also the slowest to compress and decompress.
Question 2: What does `tar -tf archive.tar` output?
- A list of filenames stored in the archive (Correct answer)
- The total file size of the archive
- Error if the archive is corrupt
- Timestamps of archived files only
Correct answer: A list of filenames stored in the archive
The -t flag lists the table of contents of a tar archive, showing each filename stored within it.
Question 3: Which option makes `zip` compress files recursively including subdirectories?
- -r (Correct answer)
- -R
- -d
- -s
Correct answer: -r
The -r option tells zip to recurse into directories and include all files and subdirectories in the archive.
Question 4: What is the result of running `bzip2 -d file.txt.bz2`?
- Decompresses to file.txt and removes file.txt.bz2 (Correct answer)
- Decompresses to file.txt and keeps file.txt.bz2
- Outputs decompressed content to stdout
- Creates file.txt.bz2.d
Correct answer: Decompresses to file.txt and removes file.txt.bz2
By default, bzip2 -d removes the compressed file and replaces it with the decompressed version.
Question 5: Which command creates a tar archive without any compression?
- tar -cf archive.tar files/ (Correct answer)
- tar -czf archive.tar.gz files/
- tar -cjf archive.tar.bz2 files/
- tar -cJf archive.tar.xz files/
Correct answer: tar -cf archive.tar files/
Using only -c and -f without -z, -j, or -J creates a plain uncompressed tar archive.
Question 6: What does `zcat file.gz` do?
- Displays the decompressed content of file.gz to stdout (Correct answer)
- Creates a new compressed file called zcat.gz
- Compares two gzip files
- Lists metadata about file.gz
Correct answer: Displays the decompressed content of file.gz to stdout
zcat is equivalent to gunzip -c and outputs the uncompressed content to standard output without modifying the file.
Question 7: Which flag tells tar to use xz compression when creating an archive?
- -J (Correct answer)
- -j
- -z
- -x
Correct answer: -J
The uppercase -J flag selects xz compression, while lowercase -j selects bzip2 and -z selects gzip.
Which compression tool generally achieves the highest compression ratio among gzip, bzip2, and xz?