250+ TOP MCQs on Compressing and Archiving Files and Answers

Unix Interview Questions and Answers for freshers on “Compressing and Archiving Files”.

1. Which of the following key options is used with tar to create an archive?
a) -c
b) -x
c) -t
d) -f archive name

Answer: a
Clarification: The tar program uses these specified key options where each key option performs a specific function.

  -c    creates an archive
  -x    extract files from an archive
  -t     display files in an archive
  -f  arch   -- specifies the archive arch.

2. To create an archive named abc.tar consisting of two files, file01 and file02, which of the following command will be used?
a) tar -cvf abc.tar file01 file02
b) tar -cvf file01 file02 abc.tar
c) tar -cv abc.tar file01 file02
d) tar -c abc.tar file01 file02

Answer: b
Clarification: To create an archive -c option is used, -v is used to display the progress while tar works while -f is used to specify the name of the archive. All these options can be combined together as (-cvf).

3. Which command will be used for extracting files from an archive named abc.tar?
a) tar -xvf abc.tar
b) tar -cvf abc.tar
c) tar -tvf abc.tar
d) tar -t abc.tar

Answer: a
Clarification: To extract files from an archive, we can use -x option along with -v and -f. Above command will extract all the files which are present in the archive named abc.tar.

4. Which of the following command is used for viewing the attributes of contents of an archive?
a) tar -tvf abc.tar
b) tar -cvf abc.tar
c) tar -xvf abc.tar
d) tar -t abc.tar

Answer: a
Clarification: -t option is used with tar for viewing the contents of the archive in a table manner. It does not extract files rather it simply shows their attributes in a suitable form containing file permissions, file size and file name.

5. Which option is used by tar to append files to the end of an archive?
a) -t
b) -c
c) -x
d) -r

Answer: d
Clarification: We can append files to an archive which is created already using -r option with tar.

$ tar  -rvf  file03  file04  abc.tar       // file03 and file04 will be added to abc.tar

6. Which command is used for compressing and archiving files together?
a) gzip and tar
b) gzip
c) bzip2
d) zip

Answer: d
Clarification: zip command combines the work of both gzip and tar i.e. it can compress and archive files together. The compression ratio using zip is lower as compared to bzip2 or gzip.

7. For using zip command, the first argument should be a compressed filename.
a) True
b) False

Answer: a
Clarification: For using zip command, the first argument should be a compressed filename, the remaining arguments are interpreted as files and directories to be compressed.

$ zip  abc.zip  file01  file02

8. For recursive compression, zip uses -r option.
a) True
b) False

Answer: a
Clarification: Just like other UNIX commands, zip command can also perform recursive compression. In recursive compression, it will compress all the subdirectories and files that will be encountered while tracing the tree structure.

9. Which command is used for unzipping files which are compressed using zip command?
a) gunzip
b) gzip
c) unzip
d) guzip

Answer: c
Clarification: unzip command is used for restoring files which are compressed using zip command. To unzip a file, simply type the filename as an argument with unzip command.

10. If the uncompressed file already exists on disk, unzip asks for the user confirmation whether to replace the existing file or not.
a) True
b) False

Answer: a
Clarification: If we invoke the following command,

$ unzip  archive.zip
Archive: archive.zip
     Inflating:  file01.html
     Inflating:  diruser_guide.txt
Replace file01.html?			//  Because file01.html already exists on disk, unzip asks the 					//  user whether to overwrite it or not.

11. Which option is used with unzip command to view the contents of a compressed archive?
a) -v
b) -t
c) -c
d) -x

Answer: a
Clarification: We can view the compressed archive using the -v option. The output list will show both compressed and uncompressed size of each file in the archive along with the percentage of compression achieved.

12. zip and unzip can perform each and every function that is performed by gzip, gunzip and tar.
a) True
b) False

Answer: a
Clarification: Using zip and unzip command we can compress, archive, uncompress files. So these two commands can perform all the functions which are performed by gzip, gunzip and tar.

Leave a Reply

Your email address will not be published. Required fields are marked *