The zip utility is a command-line tool for compressing and decompressing files on a computer. It creates a single file called a "zip archive" that contains one or more files. The archive is compressed, which reduces the size of the files and makes it easier to share or transfer them over the internet. The zip utility can also be used to password-protect the files within an archive. The unzip command is used to extract the files from a zip archive.
Let's go over the installation on Linux of the Zip Utility and how to create a Zip archive file and how to UnZip an archive file.
The Zip Utility is loaded by default on your Mac computer. Nothing is needed to support this utility.
In most Linux distributions, the Zip Utility is not pre-installed, however it can be easily installed using the package manager of the specific distribution.
$ sudo apt install unzip
$ sudo yum install unzip
You can use the -r recusive option to Zip the contents of a folder into a specific Zip file.
As an example, let’s say you have a "public" folder in your current directory, you can then add all the files into the Zip Archive with the following command. You will note that all the files are added into the same folder path that you specified so when you Unzip this Archive it will expect to creaete the same folder name with the files contained.
$ zip -r publicsite.zip public
We can simply use the -l option to list the files in the archive.
$ unzip -l myarchive.zip
When used without any options, the unzip command in its most basic form extracts all files from a specified ZIP archive to the current directory.
As an example, let’s say you downloaded a Zip file. To unzip this file to the current directory, you’d simply run the following command:
$ unzip myarchive.zip
To unzip a ZIP file to a different directory than the current one, use the -d switch:
$ unzip filename.zip -d /path/to/directory
For example, to unzip the public web content webpubic.zip to the /var/www/ directory, you’d use the following command:
$ unzip webpubic.zip -d /var/www