gunzip

file managementLinux/Unix
The gunzip command is one of the most frequently used commands in Linux/Unix-like operating systems. gunzip Decompress files compressed with gzip

Quick Reference

Command Name:

gunzip

Category:

file management

Platform:

Linux/Unix

Basic Usage:

gunzip [options] [arguments]

Common Use Cases

    Syntax

    gunzip [options] [file...]

    Options

    Option Description
    -c, --stdout Write output on standard output; keep original files unchanged
    -f, --force Force decompression even if the output file already exists
    -h, --help Display help information and exit
    -k, --keep Keep (don't delete) input files during decompression
    -l, --list List compressed file contents
    -n, --no-name Do not restore the original name and timestamp
    -N, --name Restore the original name and timestamp
    -q, --quiet Suppress all warnings
    -r, --recursive Travel the directory structure recursively
    -t, --test Test compressed file integrity
    -v, --verbose Display the name and percentage reduction for each file

    Examples

    How to Use These Examples

    The examples below show common ways to use the gunzip command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    gunzip file.txt.gz
    Decompress file.txt.gz, creating file.txt and removing the compressed file.
    gunzip -k file.txt.gz
    Decompress file.txt.gz to file.txt while keeping the original compressed file.
    gunzip *.gz
    Decompress all .gz files in the current directory. # Advanced Examples Advanced gunzip -c file.txt.gz > file.txt Decompress file.txt.gz to file.txt without removing the compressed file. gunzip -f file.txt.gz Force decompression even if file.txt already exists. gunzip -l file.txt.gz List information about the compressed file without decompressing it. find . -name "*.gz" -exec gunzip {} \; Find all .gz files in the current directory and decompress them.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The gunzip command is used to decompress files that have been compressed with the gzip utility. It effectively reverses the compression process, restoring files to their original state. Key features of gunzip: 1. File Decompression: gunzip primarily decompresses files with a .gz extension, restoring them to their original uncompressed state. 2. Multiple File Handling: gunzip can process multiple compressed files at once when provided with multiple arguments or wildcards. 3. Standard Input/Output Support: Like gzip, gunzip can read from standard input and write to standard output, making it useful in command pipelines. 4. Metadata Restoration: By default, gunzip restores the original file's name, timestamp, and permissions that were saved during compression. 5. File Management: By default, gunzip removes the compressed file after successful decompression, but this behavior can be modified with the -k option. 6. Format Support: While primarily for .gz files, gunzip can also decompress files compressed with other compatible formats like those created by compress or pack. 7. Integrity Testing: The -t option allows testing compressed files for integrity without actually extracting them. gunzip is technically a symbolic link to the gzip program; running 'gzip -d' is equivalent to running gunzip. This design reflects a common Unix philosophy where tools are often designed to do one thing well, with options to modify their behavior. The command is essential for working with compressed files in Unix-like environments, particularly when dealing with software packages, data archives, or when transferring files to save bandwidth.

    Related Commands

    These commands are frequently used alongside gunzip or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the gunzip command works in different scenarios.

    $ gunzip
    View All Commands