133

This question already has an answer here:

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?

marked as duplicate by don_crissti, cuonglm, G-Man, Michael Homer, dr01 Sep 26 '15 at 8:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

205

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
    
  • 4
    Where do I get a version of gunzip with -k or --keep? I'm using version 1.5 in Gentoo and it has no such option. – Pavel Šimerda Sep 18 '14 at 22:02
  • 1
    @PavelŠimerda It was added in version 1.6. I've amended my answer. Thanks. – Mark Plotnick Sep 18 '14 at 22:15
  • Thanks a lot! With the other option this is now the best answer. – Pavel Šimerda Sep 18 '14 at 22:21
  • 1
    @PavelŠimerda If you need --keep but don't have it, just make a copy of file.gz first. – Liam Aug 19 '15 at 16:33
  • 1
    gunzip -c file.gz > file or zcat file.gz > file also work. superuser.com/questions/45650/… – phyatt May 1 '17 at 14:38
20

Without requiring a temporary file:

 zcat somefile.gz > somefile

Not the answer you're looking for? Browse other questions tagged or ask your own question.