010-160 Archiving and Compression 5 — Questions and Answers
Question 1: What happens when you run `gzip` on a file that is already compressed (e.g., a .jpg)?
- It compresses it anyway, often resulting in a larger file (Correct answer)
- It skips the file automatically
- It reports an error and exits
- It converts it to .gz.jpg format
Correct answer: It compresses it anyway, often resulting in a larger file
gzip compresses any file regardless of type, but already-compressed formats like JPEG gain little and may even grow slightly.
Question 2: Which command extracts only a specific file from a tar archive?
- tar -xf archive.tar path/to/file.txt (Correct answer)
- tar -ef archive.tar file.txt
- tar -sf archive.tar file.txt
- tar -xf archive.tar --only file.txt
Correct answer: tar -xf archive.tar path/to/file.txt
You can specify one or more filenames after the archive name with tar -xf to extract only those specific files.
Question 3: What is the purpose of `tar --listed-incremental=snapshot.file`?
- Create an incremental backup using a snapshot file to track changes (Correct answer)
- List files changed since the last full backup
- Extract only files newer than snapshot.file
- Compare archive contents against snapshot.file
Correct answer: Create an incremental backup using a snapshot file to track changes
This option enables incremental backups by recording file metadata in the snapshot file and only archiving changed files on subsequent runs.
Question 4: Which command shows compression statistics like compressed size, original size, and ratio for a .gz file?
- gzip -l file.gz (Correct answer)
- gzip -v file.gz
- gzip -t file.gz
- gzip -s file.gz
Correct answer: gzip -l file.gz
The -l (list) option displays compression statistics including compressed size, uncompressed size, and compression ratio.
Question 5: What does `tar -uvf archive.tar newfile.txt` do?
- Appends newfile.txt only if it is newer than the version in the archive (Correct answer)
- Updates all files in the archive from the current directory
- Replaces newfile.txt in the archive unconditionally
- Creates a new archive if archive.tar does not exist
Correct answer: Appends newfile.txt only if it is newer than the version in the archive
The -u (update) flag adds files to the archive only if they are newer than the existing archived version.
Question 6: Which decompression command is the correct counterpart to `xz`?
- unxz
- xz -d
- Both unxz and xz -d work (Correct answer)
- xzcat
Correct answer: Both unxz and xz -d work
Both `unxz` (a symlink to xz) and `xz -d` decompress .xz files — they are functionally equivalent.
Question 7: What does the `cpio` command primarily do in Linux?
- Creates and extracts archives, often used with find for backup (Correct answer)
- Compresses files using the CPIO algorithm
- Copies files between two remote hosts securely
- Manages compressed partition images
Correct answer: Creates and extracts archives, often used with find for backup
cpio is an archiving tool that copies files to and from archives and is commonly piped with find to create backups.
What happens when you run `gzip` on a file that is already compressed (e.g., a .jpg)?