Explore the essential functions, commands, and features of file compression and archiving tools used in command-line interfaces. This quiz helps you assess your understanding of syntax, use-cases, and differences between common CLI tools for managing files efficiently.
Which CLI tool would you use to compress multiple files into a single archive while preserving the directory structure?
Explanation: The correct answer is 'tar' because it is specifically designed to gather multiple files and directories into a single archive file, preserving hierarchy and structure. 'cmp' is used for file comparison, not compression or archiving. 'grep' is a searching tool that finds patterns within files. 'ls' simply lists files in a directory, without any compression or archiving capabilities.
If you see a file named 'backup.tar.gz', which process was most likely used to create it from a folder?
Explanation: 'backup.tar.gz' suggests that 'tar' was first used to create an archive, then 'gzip' was applied to compress it, resulting in the dual extension. Compressing with gzip alone does not create a .tar.gz file without an archive step. The 'zip' format produces .zip files, not .tar.gz. 'bzip2' produces .bz2 extensions, not .gz.
Which CLI tool provides lossless compression for individual files without combining them into an archive?
Explanation: The correct answer is 'gzip', which compresses single files without creating an archive. 'tar' is for archiving and does not compress by itself unless combined with another utility. 'diff' compares files, and 'cat' displays file contents without any compression features.
Which command would you typically use to extract all files from an archive named 'documents.zip' in the CLI?
Explanation: 'unzip documents.zip' is the standard command to extract files from a zip archive using CLI tools. 'untar' is not a common tool or command for zip files. 'gunzip' handles gzip-compressed files, not zip archives. 'extract' is not a universal command provided by standard CLI environments.
Which option would add verbose output and maximum compression while creating a compressed tar archive in a bash shell?
Explanation: 'tar -cvzf archive.tar.gz folder/' combines the creation (-c), verbose output (-v), gzip compression (-z), and output file (-f) options, making it suitable for this task. 'tar -xf' is used for extraction, not creation. 'tar -czl' uses an incorrect option (-l), which is not standard for maximum compression. 'tar -rvzf' involves appending files rather than creating a new archive, and uses improper extension for a tar archive.