If you have an Ubuntu/Debian server installation and need to open or create Zip file then you need to install the necessary packages to work with Zip files. Fortunately, we can easily add support for Zip to our installation by installing two packages(Zip, Unzip) both available from the repositories.
Note: This post assumes you have the ability to install packages, root or sudo access.
Creating a Zip Archive
Install Zip from the repositories.
# apt-get install zip
The entire process is quite simple to understand.
# zip -r new-file-name.zip directory-to-compress/
- zip – This is the name of the application we will be using to compress
- -r – Short for Recursive, only use this option is you are creating a compressed archived from a directory
- new-file-name.zip – Name of the resulting compressed archive, the naming is up to you
- directory-to-compress/ – Name of the directory we are about to compress
It is possible to add more than one directory in to the same archive.
# zip -r new-file-name.zip directory-1/ directory-2/
But, what if I only need to compress a single file. Similar process except we don’t need to use the -r(recurse) option.
# zip report.zip LitenDuplicateReport.csv
Opening a Zip archive
Opening or extracting the contents from a compressed archive is handled not by the Zip package but by a second package called Unzip.
# apt-get install unzip
With Unzip you have two options as to how the contents will be extracted, either you can extract the contents of the compressed archive to a directory or simply extract the contents to the current directory.
# unzip nc111nt.zip -d netcat/
- unzip – Tool that will extract contents from Zip compressed archive
- nc111nt.zip – Name of the archive we are extracting from
- -d – Short for destination
- netcat – Unzip will create a new directory called netcat where the contents will be extracted to
Or you can extract the contents of the archive to the current directory you are in.
# unzip nc111nt.zip
All you need is two packages and your installation will be able to work with Zip archives. I know Ubuntu/Debian have support for Gzip but if you work with Windows users and need to share files with them then Zip might be the only way to go.