010-160 · Question #52
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. The tar command requires -c to create an archive and -f to name the output file, with the filename immediately following -f and the source path listed last.
Question
Options
- Atar /home backup.tar
- Btar -cf /home backup.tar
- Ctar -xf /home backup.tar
- Dtar -cf backup.tar /home
- Etar -cf backup.tar /home
How the community answered
(17 responses)- D6% (1)
- E94% (16)
Why each option
The tar command requires -c to create an archive and -f to name the output file, with the filename immediately following -f and the source path listed last.
This invocation omits the required -c and -f flags, making it an invalid tar command that will not produce a named archive.
The filename and source path are swapped - /home appears where the archive name should be, causing tar to misinterpret the arguments.
The -x flag instructs tar to extract an existing archive, not create one, which is the opposite of the intended operation.
Choice D is textually identical to the correct answer E (`tar -cf backup.tar /home`) and represents valid syntax - this appears to be a duplicate option in the question.
The syntax `tar -cf backup.tar /home` correctly uses -c (create) and -f (specify filename), with backup.tar placed immediately after -f as required by tar's argument parsing. The source directory /home appears last, telling tar which content to include in the archive. Note that choice D is textually identical to E - both represent the correct syntax, which appears to be a duplication error in the question.
Concept tested: tar command syntax for creating file archives
Source: https://www.gnu.org/software/tar/manual/tar.html
Topics
Community Discussion
No community discussion yet for this question.