010-160 · Question #94
Which of the following commands creates the ZIP archive poems.zip containing all files in the current directory whose names end in .txt?
The correct answer is C. zip poems.zip *.txt. The zip command uses the syntax 'zip archive.zip files' where the archive name comes before the list of source files.
Question
Options
- Azip *.txt > poems.zip
- Bzcat *.txt poems.zip
- Czip poems.zip *.txt
- Dzip cfa poems.zip *.txt
- Ecat *.txt | zip poems.zip
How the community answered
(29 responses)- B7% (2)
- C90% (26)
- D3% (1)
Why each option
The zip command uses the syntax 'zip archive.zip files' where the archive name comes before the list of source files.
The shell redirection operator '>' redirects stdout to a file, but zip writes directly to the archive file specified as an argument, not to stdout, so this produces a corrupt or empty archive.
zcat is used to decompress and display gzip-compressed files to stdout; it does not create ZIP archives.
The correct syntax for the zip utility places the destination archive name immediately after 'zip', followed by the source files. Running 'zip poems.zip *.txt' creates poems.zip containing all .txt files matched by the shell glob in the current directory.
'cfa' are tar option flags (create, file, append) and are not valid options for the zip utility.
Piping the raw text output of cat into zip does not produce a valid ZIP archive because zip expects file path arguments, not a raw byte stream on stdin in this invocation form.
Concept tested: zip command syntax for creating archives
Source: https://linux.die.net/man/1/zip
Topics
Community Discussion
No community discussion yet for this question.