First up install the zip and unzip packages if you haven’t already!
sudo apt-get install zip sudo apt-get install unzip
OR
sudo apt-get install zip unzip
If you are Red Hat Linux/Fedora/CentOS Linux user then you can use the yum command to install zip and unzip program as follows:
# yum install zip # yum install unzip
A few ziping files/directories examples
Creates the archive data.zip and puts all the files in the current directory in it in compressed form, type:
zip data *
Note: No need to add .zip extension or suffix as it is added automatically by zip command.
Use the ls
command view a current files and verify new zip file:
ls
To zip up an entire directory (including all sub directories), type the following command:
zip -r data *
unzipping files/directories examples
To use unzip to extract all files of the archive photos.zip into the current directory & sub directories:
unzip photos.zip
You can also test photos.zip, printing only a summary message indicating whether the archive is OK or not:
unzip -tq photos.zip
To extract the file called cv.doc from pics.zip:
unzip photos.zip cv.doc
To extract all files into the /tmp directory:
unzip photos.zip -d /tmp
To list all files from photos.zip:
unzip -l photos.zip