Unzipping a .gz file without removing the gzipped file

I have a file file.gz, when I try to unzip this file by using gunzip file.gz, it unzipped the file but only contains extracted and removes the file.gz file.

How can I unzip by keeping both unzipped file and zipped file?

Asked By: jack


Without requiring a temporary file:

 zcat somefile.gz > somefile
Answered By: LatinSuD

Here are several alternatives:

  • Give gunzip the --keep option (version 1.6 or later)

    -k   --keep
            Keep (don’t delete) input files during compression or decompression.

    gunzip -k file.gz
  • Pass the file to gunzip as stdin

    gunzip < file.gz > file
  • Use zcat (or, on older systems, gzcat)

    zcat file.gz > file
Answered By: Mark Plotnick
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.