nerdexam
LPI

010-100 · Question #19

Which of the following commands will create an archive file, named backup.tar, containing all the files from the directory /home?

The correct answer is E. tar -cf backup.tar /home. Creating a tar archive requires the -c flag to create and -f to specify the filename, with the archive name listed before the source path.

The Power of the Command Line

Question

Which of the following commands will create an archive file, named backup.tar, containing all the files from the directory /home?

Options

  • Atar /home backup.tar
  • Btar -cf /home backup.tar
  • Ctar -xf /home backup.tar
  • Dtar -xf backup.tar /home
  • Etar -cf backup.tar /home

How the community answered

(27 responses)
  • A
    4% (1)
  • B
    11% (3)
  • D
    4% (1)
  • E
    81% (22)

Why each option

Creating a tar archive requires the -c flag to create and -f to specify the filename, with the archive name listed before the source path.

Atar /home backup.tar

No operation flag is given, so tar cannot determine whether to create, extract, or list, and the argument positions are also incorrect.

Btar -cf /home backup.tar

The archive filename and source path are swapped - this would attempt to create an archive named /home containing a file called backup.tar.

Ctar -xf /home backup.tar

The -x flag signals extraction, not creation, so this would attempt to extract rather than create an archive, and the argument order is also reversed.

Dtar -xf backup.tar /home

The -x flag signals extraction, not creation, so this command would try to extract backup.tar rather than create a new archive from /home.

Etar -cf backup.tar /homeCorrect

tar -cf backup.tar /home uses -c to signal archive creation and -f to designate the output filename as backup.tar, followed by the source directory /home. The argument order is critical - the filename must immediately follow -f, and the source paths come last. This is the correct POSIX tar syntax for creating a new archive from a directory.

Concept tested: tar archive creation with -c and -f flags

Source: https://www.gnu.org/software/tar/manual/tar.html

Topics

#tar command#archive creation#tar options#backup

Community Discussion

No community discussion yet for this question.

Full 010-100 Practice