010-160 · Question #96
Which of the following commands extracts the contents of the compressed archive file1.tar.gz?
The correct answer is C. tar -xzf file1.tar.gz. Extracting a .tar.gz file requires the tar flags -x (extract), -z (gzip decompression), and -f (specify filename).
Question
Options
- Atar -czf file1.tar.gz
- Btar -xf file1.gz
- Ctar -xzf file1.tar.gz
- Dtar --extract file1.tar.gz
- Edetar file1.tar.gz
How the community answered
(34 responses)- A3% (1)
- C91% (31)
- D6% (2)
Why each option
Extracting a .tar.gz file requires the tar flags -x (extract), -z (gzip decompression), and -f (specify filename).
The -c flag creates a new archive rather than extracting; -czf would compress and create file1.tar.gz, the opposite of extracting it.
This command omits the -z flag needed to handle gzip decompression, and references an incorrect filename (file1.gz) that does not match the actual archive file1.tar.gz.
The flags -x (extract), -z (filter through gzip), and -f (use the named file as the archive) together correctly decompress and unpack a .tar.gz archive. Running 'tar -xzf file1.tar.gz' fully restores all files stored in the compressed tar archive.
The --extract flag alone without -z and a proper -f filename argument cannot decompress and extract a gzip-compressed tar archive correctly.
'detar' is not a valid Linux command and no such standard utility exists for extracting tar archives.
Concept tested: tar flags for extracting gzip-compressed archives
Source: https://www.gnu.org/software/tar/manual/tar.html
Topics
Community Discussion
No community discussion yet for this question.