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 = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, perl, php, python, java, javascript, nodejs, angular, react); plays_on(xbox, ps4); linux_desktop_user(true); }