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?
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?
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
Without requiring a temporary file:
zcat somefile.gz > somefile
zcat file.sql.gz | mysql --max_allowed_packet=32M db
– Soheil
Sep 19 '21 at 19:25
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--keep
but don't have it, just make a copy offile.gz
first. – Liam Aug 19 '15 at 16:33gunzip -c file.gz > file
orzcat file.gz > file
also work. https://superuser.com/questions/45650/how-do-you-gunzip-a-file-and-keep-the-gz-file/45651 – phyatt May 01 '17 at 14:38cat thing1.gz thing2.gz > both.gz; gunzip -k both.gz
will produce a single file namedboth
and won't deleteboth.gz
. The gzip man page recommends that, if you need to compress multiple flles while preserving all their names, you use something liketar
to bundle them up and give tar thez
option to gzip the entire bundle. – Mark Plotnick Mar 29 '19 at 18:51
– Worp May 03 '19 at 06:59# gunzip -k my.gz gzip: invalid option -- 'k' Try 'gzip --help' for more information.
gunzip --version
? The -k option is only in version 1.6 and beyond. – Mark Plotnick May 03 '19 at 08:43$ gunzip --version gunzip (gzip) 1.5
My bad, I will edit my comment! edit: I can't edit my comment anymore, so let's leave this up for clarification. Thanks for the info! – Worp May 03 '19 at 08:56