How can I create and extract zip archives from the command line?
Best Answer
Typically one uses tar to create an uncompressed archive and either gzip or bzip2 to compress that archive. The corresponding gunzip and bunzip2 commands can be used to uncompress said archive, or you can just use flags on the tar command to perform the uncompression.
If you are referring specifically to the Zip file format, you can simply use the zip and unzip commands.
Restoring permissions is a feature of unzip (from the man page, version 6.00):
Dates, times and permissions of stored directories are not restored
except under Unix. (On Windows NT and successors, timestamps are now
restored.)
and there is no option to switch if off.
It might be that an older version of unzip did not support restoring permission, but investigating that route is probably more cumbersome than trying to change the latest unzip source to do what you want.
If running chmod -R is unacceptable you can take a look at using Python's zipfile library, it is easy to use and gives you full control over the way you write the files that you extract from the zip file.
If, after extraction, the new directory contains exactly one subdirectory, then move all of the files inside it up one level and get rid of the original subdirectory.
By the way, making an archive (tar, zip, whatever) without having all of the members of the archive inside of a subdirectory is EVIL. I don't know why people do it!
Best Answer
Typically one uses
tar
to create an uncompressed archive and eithergzip
orbzip2
to compress that archive. The correspondinggunzip
andbunzip2
commands can be used to uncompress said archive, or you can just use flags on thetar
command to perform the uncompression.If you are referring specifically to the Zip file format, you can simply use the
zip
andunzip
commands.To compress:
or to zip a directory
To uncompress:
this unzips it in your current working directory.