Reputation: 91
New to Linux
had gzip the folder as abc.gz. now when i try using the gunzip command the file doesn't come as folder, instead the output file has become abc. could someone let me know the command to unzip the abc.gz as a folder.
thanks
Upvotes: 9
Views: 17040
Reputation: 477881
gzip
compresses one single file, and doesn't store the original filename (you could for instance compress a network stream you captured once, that didn't had a name) into that file. If you need to compress multiple files, you need to make use of a tarball (a collection of files packed into a single file, a tarball stores the name of the files as well).
When you read the manual of gzip
(man gzip
), you can see that you simply use
gzip -d < "file.gz" > "realfile.dat"
to decompress the file stored in "file.gz" and save it as "realfile.dat".
Now if you have compressed multiple files, you need to do this using the earlier called tarball. Perhaps you dropped the extension. In that case, you can first decompress the .gz
file and then use tar
to expand it using:
gzip -d < "file.tar.gz" | tar -x
Here tar
reads from stdin
(data provided by gzip
and expands it). Since people use gzip
on tar
a lot of times, tar
made it more convenient using:
tar -xzf "file.tar.gz"
where z
means you want to run gzip
on it, and f
means that you read from a file instead of the stdin
.
In order to create such archive, you again first need to use tar:
tar -c "folder" | gzip -c > "file.tar.gz"
Or, tar
again comes up with a shorter way to do this:
tar -czf "file.tar.gz" "folder"
Upvotes: 10
Reputation: 9893
gunzip
functions as a decompression algorithm only.
so gunzip
would simply leave with the file decompressed, on which you would then need e.g. to tar xvf file.tar
.
The z
option of tar
is simply a shortcut to do the decompression with gzip
along with extracting the files.
Upvotes: 3