Commands.page Logo

How to Decompress GZ File Keeping Original in Ubuntu

Managing compressed archives is a routine task for Ubuntu users. Often, the default extraction tools delete the source file upon completion, which is not always desired. This guide provides the specific command line instructions needed to decompress .gz files while ensuring the original compressed archive remains intact on your system.

By default, the gunzip command removes the .gz file after extracting its contents. To stop this from happening, you must add a specific flag to your command. The primary solution is to use the -k option, which tells the utility to keep the input file.

To decompress a file named archive.gz without deleting it, run:

gunzip -k archive.gz

You can also achieve the same result using the gzip command with the decompress flag. The syntax for this method is:

gzip -dk archive.gz

In both examples, the -k flag ensures the original .gz file is preserved. The uncompressed file will appear in the same directory alongside the original archive. This method is efficient for maintaining backups or sharing the compressed file after viewing its contents.