nerdexam
LPI

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.

The Power of the Command Line

Question

Which of the following commands creates the ZIP archive poems.zip containing all files in the current directory whose names end in .txt?

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)
  • B
    7% (2)
  • C
    90% (26)
  • D
    3% (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.

Azip *.txt > poems.zip

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.

Bzcat *.txt poems.zip

zcat is used to decompress and display gzip-compressed files to stdout; it does not create ZIP archives.

Czip poems.zip *.txtCorrect

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.

Dzip cfa poems.zip *.txt

'cfa' are tar option flags (create, file, append) and are not valid options for the zip utility.

Ecat *.txt | zip poems.zip

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

#zip command#file compression#archiving#command syntax

Community Discussion

No community discussion yet for this question.

Full 010-160 Practice