vote up 5 vote down star
1

The default behavior of gunzip is to delete the .gz file after it decompresses.

How do I prevent it from deleting the file??

If this functionality is not included then is there an alternative program that allows this?

I'm using Ubuntu 9.04

flag

migrated from stackoverflow.com

6 Answers

vote up 12 vote down check

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
link|flag
Thanks for the answer. Growing up with pkunzip in DOS I find it so strange that there isn't an option to keep the file. Especially with a tool like gzip being so widely used... just weird. – Sen Sep 23 at 14:59
1  
FYI, I actually don't have gzcat. Neither my local system or the system I was ssh'ed into. So, I have to use gunzip -c – Sen Sep 23 at 16:15
1  
it's probably just zcat on your system. – justin Jan 31 at 14:52
vote up 15 vote down

You can the -c option 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.

link|flag
vote up 3 vote down

Use the -c option to uncompress the file to stdout. It will not touch the original file.

gunzip -c myfile.gz > myfile
link|flag
vote up 3 vote down

If it's actually a tarball (.tgz or .tar.gz extension), then instead of redirecting to file like all of the answers so far, you'll want to pipe it to tar, like so:

gunzip -c myfile.tar.gz | tar xvf -

so that you get the actual contents.

link|flag
2  
or just do: tar xzvf myfile.tar.gz – Joakim Elofsson Sep 23 at 17:39
true, but only if you have GNU tar. The one that comes with Solaris, for example, doesn't support the z option. – Alex Sep 23 at 20:01
vote up 2 vote down

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

gunzip < myfile.gz > myfile
link|flag
vote up 0 vote down

Gnu tar can read gzip files: tar -zxsvf myfile.tar.gz or tar -jxzvf myfile.tar.bz2 for bzipped tar files.

link|flag

Your Answer

Get an OpenID
or
never shown

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