How do you gunzip a file and keep the .gz file?

You're looking for:

gzcat x.txt.gz >x.txt

The gzcat command is equivalent to gunzip -c which simply writes the output stream to stdout. This will leave the compressed file untouched. So you can also use:

gunzip -c x.txt.gz >x.txt

Note that on some systems gzcat is also known as zcat so run like this instead:

zcat x.txt.gz >x.txt

You can use the -c option of gunzip which writes the output to stdout, and then pipe it to the file of your choice:

gunzip -c compressed-file.gz > decompressed-file

More details on the manual page.


A simpler solution is to just use gunzip as a filter like this:

gunzip < myfile.gz > myfile

Tags:

Linux

Gunzip

Gz