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.
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)- A4% (1)
- B11% (3)
- D4% (1)
- E81% (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.
No operation flag is given, so tar cannot determine whether to create, extract, or list, and the argument positions are also incorrect.
The archive filename and source path are swapped - this would attempt to create an archive named /home containing a file called 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.
The -x flag signals extraction, not creation, so this command would try to extract backup.tar rather than create a new archive from /home.
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
Community Discussion
No community discussion yet for this question.