010-160 Archiving and Compression 2 — Questions and Answers
Question 1: Which tar option extracts files to a specific directory instead of the current one?
- -C /path/to/dir (Correct answer)
- -D /path/to/dir
- -X /path/to/dir
- -O /path/to/dir
Correct answer: -C /path/to/dir
The -C option changes the working directory before performing any operations, so files are extracted there.
Question 2: What does the `gzip -k` flag do?
- Keep the original file after compression (Correct answer)
- Use maximum compression level
- Skip already-compressed files
- Compress using a symmetric key
Correct answer: Keep the original file after compression
The -k (keep) flag tells gzip to retain the original file instead of replacing it with the compressed version.
Question 3: Which command lists the contents of a .tar.bz2 file without extracting it?
- tar -tjf archive.tar.bz2 (Correct answer)
- tar -xjf archive.tar.bz2
- tar -czf archive.tar.bz2
- tar -djf archive.tar.bz2
Correct answer: tar -tjf archive.tar.bz2
The -t flag lists contents, -j specifies bzip2, and -f specifies the filename — no extraction occurs.
Question 4: What compression format does the `xz` command produce by default?
- .xz using LZMA2 (Correct answer)
- .bz2 using Burrows-Wheeler
- .gz using DEFLATE
- .lz using LZ77
Correct answer: .xz using LZMA2
The xz utility uses the LZMA2 algorithm and produces files with the .xz extension by default.
Question 5: Which tar option appends files to an existing uncompressed tar archive?
- -r (Correct answer)
- -a
- -u
- -p
Correct answer: -r
The -r (append) option adds files to the end of an existing archive without recreating it.
Question 6: What is the purpose of `tar --exclude='*.log'` when creating an archive?
- Skip all files matching the pattern *.log (Correct answer)
- Delete .log files after archiving
- Only archive .log files
- Extract only non-.log files
Correct answer: Skip all files matching the pattern *.log
The --exclude option tells tar to skip any files matching the given pattern during archive creation.
Question 7: Which command decompresses a .xz file while keeping the original compressed file?
- xz -dk file.xz (Correct answer)
- xz -f file.xz
- xz -c file.xz
- xz -t file.xz
Correct answer: xz -dk file.xz
The -d decompresses and -k keeps the original, so both the compressed and decompressed files remain.
Which tar option extracts files to a specific directory instead of the current one?