010-160 Archiving and Compression 3 — Questions and Answers
Question 1: What does `tar -cvzf backup.tar.gz /home/user` do?
- Creates a gzip-compressed archive of /home/user with verbose output (Correct answer)
- Extracts a gzip archive to /home/user verbosely
- Creates a bzip2 archive of /home/user
- Lists the contents of backup.tar.gz
Correct answer: Creates a gzip-compressed archive of /home/user with verbose output
Flags -c (create), -v (verbose), -z (gzip), -f (filename) together create a compressed tar archive.
Question 2: Which utility can both compress files and create archives (unlike gzip which only compresses)?
- zip (Correct answer)
- bzip2
- xz
- compress
Correct answer: zip
The zip utility creates archive files containing multiple files with compression, while gzip/bzip2/xz only compress single files.
Question 3: What does `gunzip -c file.gz` do?
- Decompresses to stdout without modifying the original file (Correct answer)
- Decompresses and creates file with .c extension
- Compresses file.gz further
- Checks integrity of file.gz
Correct answer: Decompresses to stdout without modifying the original file
The -c flag writes decompressed output to standard output (stdout), leaving the original .gz file intact.
Question 4: Which command tests the integrity of a gzip-compressed file without decompressing it?
- gzip -t file.gz (Correct answer)
- gzip -l file.gz
- gzip -c file.gz
- gzip -d file.gz
Correct answer: gzip -t file.gz
The -t option tests the compressed file's integrity by verifying checksums without writing any output files.
Question 5: What extension does `bzip2` add to a compressed file by default?
- .bz2 (Correct answer)
- .bz
- .bzip
- .b2
Correct answer: .bz2
By default, bzip2 appends .bz2 to the original filename, so file.txt becomes file.txt.bz2.
Question 6: Which tar flag preserves file permissions and ownership during extraction?
- -p (Correct answer)
- -o
- -P
- -m
Correct answer: -p
The -p (preserve permissions) flag instructs tar to restore the original permissions of extracted files.
Question 7: What does `unzip -l archive.zip` do?
- Lists the contents of archive.zip without extracting (Correct answer)
- Extracts archive.zip to a list of directories
- Deletes listed files from archive.zip
- Lists zip archives in the current directory
Correct answer: Lists the contents of archive.zip without extracting
The -l option displays the file listing inside the zip archive including sizes and dates, without extracting anything.
What does `tar -cvzf backup.tar.gz /home/user` do?