I'm trying to zip a folder in unix. Can that be done using the gzip command?
|
No. Unlike Because of various reasons some of which hearken back to the era of tape drives, Unix uses a program named In order to "zip" a directory, the correct command would be
This will tell The
To decompress and unpack the archive into the current directory you would use
That command is effectively the same as
|
|||||||||||||||||
|
|
The Examplebefore
now run the
after
If you'd prefer to zip up the directory structure then you'll likely want to use the
Example
Which results in the following single file:
You can confirm its contents:
|
|||
|
|
|
I scripted these 2 commands:
(!!!) Please test before use (as there is a 'rm -f' which could potentially remove important data if used in an uncommon way). How to use
Will create /home/MyDirectory.tgz and remove MyDirectory on success (!!!).
Will create /home/MyDirectory and remove /home/MyDirectory.tgz on success. |
|||||
|
|
If your linux tar doesn't support the
|
||||
|
|
|
I recommend using
|
|||
|
|
|
The Answer to the question “Can I zip an entire folder using gzip?” is to use the syntax:
|
|||||||||||||
|
gzip -r myfolderwhich will gzip files recursively. The same way you can unzip files usinggunzip -r myfolderwhich will unzip files recursively. For more information,man gzip– val0x00ff Oct 1 '13 at 8:27tar; it supports options for compression.gzipis designed as a complement totar, not as a replacement. – devnull Oct 1 '13 at 8:38commentsince that was not the answer to his question. – val0x00ff Oct 1 '13 at 12:191and2under folderplayground.gzip -r ./playgroundwill give you1.gzand2.gz(and no more1and2files) under folderplayground, NOT a zipped file with everything in it. – Jeff Xiao Oct 5 '16 at 12:13