Unix / Linux: Gunzip and Keep Original Files Unchanged

Objective: Gunzip, by default will delete the .gz file after decompression. Learn how to retain the original files after extracting the .gz file.

The first method to keep the original .gz files is to use the -c option of gunzip. The -c option will write the decompressed data to stdout and will not remove the original .gz file. To extract the file foo.gz to foo while keeping the foo.gz file, use the following syntax.

$ gunzip -c foo.gz > foo

ls -l
total 2808
-rw-r--r-- 1 root root 2150400 Aug  7 15:10 foo
-rw-r--r-- 1 root root  724005 Aug  7 15:09 foo.gz

The output of gunzip is redirected to the decompressed file called foo.

The other method is to use zcat instead of gunzip -c.

$ zcat foo.gz > foo

If the gzcat utility is not available on your system, try using zcat instead.

Ibrahim is a technology enthusiast with a keen interest in *NIX (Unix, Linux) systems, Android, open source and other tech related stuff. When his cpu load is low, you can probably find him online playing on his Xbox or PlayStation.