When you download software source code, database backups, or massive log files on a Linux system, they are almost always compressed using the GNU zip (gzip) format to save bandwidth. These files typically end with a .gz extension. Before you can read the text inside or compile the software, you must extract the original file and remove the compression. The standard tool for doing this in any Linux terminal is the gunzip command.
How the gunzip Command Works
The gunzip command is incredibly straightforward. When you point it at a .gz file, it reads the compressed binary data, recreates the original uncompressed file on your hard drive, and then automatically deletes the compressed .gz archive to save space.
Basic Extraction
To extract a single gzip file, simply open your terminal, navigate to the directory containing your file, and type gunzip followed by the filename.
gunzip backup_2025.txt.gz
After you press Enter, the command will execute silently. If you run the ls command to list your files, you will see that backup_2025.txt.gz has completely disappeared, replaced by the fully uncompressed backup_2025.txt.
How to Keep the Original Compressed File
By default, gunzip destroys the .gz archive once the extraction is complete. This is usually desirable, but if you are extracting a massive backup file for a quick inspection and want to keep the compressed version stored safely on your drive, this behavior is problematic.
To force the utility to extract the file without deleting the original archive, use the -k (keep) flag.
gunzip -k database_dump.sql.gz
This command will result in two identical files existing side-by-side on your hard drive: the compressed database_dump.sql.gz and the uncompressed, readable database_dump.sql.
Extracting Multiple Files Simultaneously
If you have downloaded a folder containing dozens of compressed log files (e.g., log1.gz, log2.gz, log3.gz), you do not need to run the command manually for each one. You can use standard bash wildcards to extract them all in a single sweep.
gunzip *.gz
This will instantly locate every gzip archive in your current directory and uncompress them all simultaneously, deleting the original archives as it goes.