Linux File Compression u0026 Archiving: tar, zip, gzip Quiz Quiz

Explore key concepts of Linux file compression and archiving with this quiz based on tar, zip, and gzip. Assess your understanding of practical command-line usage, file handling strategies, and the differences among common Linux utilities.

  1. Compressing Multiple Files into One Archive

    Which command creates a compressed archive named data.tar.gz from the files notes.txt and report.csv in Linux?

    1. tar -czf data.tar.gz notes.txt report.csv
    2. tar -xzf data.tar.gz notes.txt report.csv
    3. gzip tar data.tar.gz notes.txt report.csv
    4. zip -c data.tar.gz notes.txt report.csv

    Explanation: The correct option uses 'tar -czf' to create (-c), compress with gzip (-z), and specify the output file (-f). This is the standard way to create a gzip-compressed tarball. The 'zip -c' command is incorrect syntax, as 'zip' archives rather than using tar. The 'gzip tar data.tar.gz' option is not a valid command structure and mixes up utilities. The 'tar -xzf' option is for extracting, not creating, an archive.

  2. Extracting Archive Contents

    If you want to extract all files from an existing archive called backup.zip into the current directory, which command should you use?

    1. zip -e backup.zip
    2. unzip backup.zip
    3. tar -xf backup.zip
    4. gunzip backup.zip

    Explanation: 'unzip backup.zip' is the correct command to extract files from a zip archive in Linux. The 'gunzip' command is only for files compressed with gzip, not zip archives. The 'tar -xf' option is used for tar archives, not .zip files. The 'zip -e' command is used to create encrypted zip archives, not for extraction.

  3. Understanding gzip Compression

    After running 'gzip log.txt', what will be the result in your directory?

    1. A tar archive named log.tar will be created.
    2. A compressed file named log.txt.gz will appear, while log.txt will be removed.
    3. Both log.txt and log.txt.gz will exist in the directory.
    4. log.txt will be moved to a subfolder named gzip.

    Explanation: The 'gzip' command compresses the file and replaces it with a '.gz' version, removing the original by default. Keeping both files would require an option like '-k', which is not mentioned. A tar archive, such as 'log.tar', is created using 'tar', not 'gzip'. Files are not automatically moved into a subfolder because gzip simply compresses the file in place.

  4. Choosing the Right Archiving Tool

    When should you use the 'zip' utility instead of 'tar' or 'gzip' for your files?

    1. When creating an archive for exclusive extraction by tar only.
    2. When compressing large database dumps only for internal scripts.
    3. When you need a single cross-platform archive readable by both Linux and many non-Linux systems.
    4. When you require archiving without any compression.

    Explanation: The 'zip' format is widely supported across different operating systems, making it ideal for creating archives to share between platforms. Tar and gzip are commonly used for archiving and compressing in Linux environments, especially for scripts or system backups, but are less universally supported outside of Unix-like systems. Tar-only archives do not offer built-in cross-platform features or compression. Archiving without compression would typically involve 'tar' alone, not 'zip'.

  5. Viewing Archive Contents without Extraction

    Which command displays the list of files inside the compressed archive archive.tar.gz without extracting them?

    1. gzcat archive.tar.gz
    2. gzip -L archive.tar.gz
    3. tar -tzf archive.tar.gz
    4. zip -l archive.tar.gz

    Explanation: 'tar -tzf' lists files in a compressed tar archive without unpacking them, which is often useful for previewing contents. The 'gzcat' command is for viewing the uncompressed data but does not list file names within the archive. 'zip -l' is only for listing contents in zip archives, not tarballs. 'gzip -L' is not a valid option for inspecting files in tar.gz archives.