nerdexam
CompTIA

XK0-004 · Question #499

A technician wants to archive and compress all files and folders contained within the /home/user directory. Which of the following commands should the technician execute?

The correct answer is B. tar cvfz ./user.tar.gz /home/user. The tar command requires specific flags to create a gzip-compressed archive. The correct flag order and compression option must match the intended output file format.

System Management

Question

A technician wants to archive and compress all files and folders contained within the /home/user directory. Which of the following commands should the technician execute?

Options

  • Atar xvfz /home/user user.tar.z
  • Btar cvfz ./user.tar.gz /home/user
  • Ctar cvfx user.tar.zip /home/user
  • Dtar xfvZ user.tar.Z ./home/user

How the community answered

(54 responses)
  • A
    2% (1)
  • B
    93% (50)
  • C
    4% (2)
  • D
    2% (1)

Why each option

The tar command requires specific flags to create a gzip-compressed archive. The correct flag order and compression option must match the intended output file format.

Atar xvfz /home/user user.tar.z

The 'x' flag extracts an archive rather than creating one, making this command attempt to decompress rather than compress.

Btar cvfz ./user.tar.gz /home/userCorrect

The 'c' flag creates a new archive, 'v' enables verbose output, 'f' specifies the output filename, and 'z' applies gzip compression - all required to produce a .tar.gz file. The destination archive path comes before the source directory, which is the correct tar syntax for creation. This command will recursively archive and compress all contents of /home/user into ./user.tar.gz.

Ctar cvfx user.tar.zip /home/user

The 'x' flag again specifies extraction, and tar has no native 'zip' compression flag - .zip is not a valid tar compression format.

Dtar xfvZ user.tar.Z ./home/user

The 'x' flag specifies extraction, 'Z' denotes compress (legacy .Z format) not gzip, and the argument order places the source path after the archive name which is incorrect for creation.

Concept tested: Linux tar archive creation with gzip compression

Source: https://man7.org/linux/man-pages/man1/tar.1.html

Topics

#tar#compression#archiving#gzip

Community Discussion

No community discussion yet for this question.

Full XK0-004 Practice