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
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
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
-k to keep the original file.
– schnaader
Sep 08 '11 at 20:19
alias gzcat="gunzip -c" ... Of course, I don't mind just using zcat. Less typing, more energy efficient ;)
– Buttle Butkus
Jan 08 '13 at 02:53
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
gunzip never knows what file it's getting, all it sees is a stream of data, so can't possibly alter the original file.
– Walf
Dec 09 '16 at 01:11
gunzip < database.sql.gz | mysql -uroot -p
– Timothy Zorn
Jun 07 '20 at 23:10
gzip -dk myfile.gz
OR
gunzip -k myfile.gz
Comments:
-k --keep Keep (don't delete) input files during compression or decompression.
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.
Use the -c option to uncompress the file to stdout. It will not touch the original file.
gunzip -c myfile.gz > myfile
Gnu tar can read gzip files: tar -zxsvf myfile.tar.gz or tar -jxzvf myfile.tar.bz2 for bzipped tar files.
-k. – aleksandr barakin Sep 14 '16 at 11:48