You can pass the -S
option to use a suffix other than .gz
.
gunzip -S .compressed file.compressed
If you want the uncompressed file to have some other name, run
gzip -dc <compressed-file >uncompressed-file
gunzip <compressed-file >uncompressed-file
(these commands are equivalent).
Normally unzipping restores the name and date of the original file (when it was compressed); this doesn't happen with -c
.
If you want the compressed file and the uncompressed file to have the same name, you can't do it directly, you need to either rename the compressed file or rename the uncompressed file. In particular, gzip
removes and recreates its target file, so if you need to modify the file in place because you don't have write permission in the directory, you need to use -c
or redirection.
cp somefile /tmp
gunzip </tmp/somefile >|somefile
Note that gunzip <somefile >somefile
will not work, because the gunzip
process would see a file truncated to 0 bytes when it starts reading. If you could invoke the truncation, then gunzip
would feed back on its own output; either way, this one can't be done in place.
The command you're showing in your first line (tar -cvfz example2.tgz example1
) doesn't work and it should not output any file example2.tgz
. Didn't you get an error? Perhaps the file example2.tgz
existed already? Check if you have a file called z
in that folder - that's where the tgz has been saved to, because:
The -f
parameter specifies the file which must follow immediately afterwards: -f <file>
Try
tar cvzf exam.tgz example1
Best Answer
You could decompress to standard output and feed it through something like
head
to only capture a bit of it:The
-c
flag tohead
requires thehead
implementation that is provided by GNU coreutils.dd
may also be used:Both of these pipelines will copy the first 20 MiB of the uncompressed file to
file.part
.