How to use zip on the command line

Some simple examples on how to use Zip on the Linux command line.

To compress a single file:
zip backup.zip apache.log

This will package the file apache.log into a zip file called backup.zip. The original apache.log file will not be deleted by zipping it. If backup.zip does not exist it will be created in the current working directory. If an archive with this name already exists the file will be added to backup.zip.

To back up a directory you need to add the -r (as in recursive) parameter. To create an archive of the /etc directory in your current working directory:
zip -r archive.zip /etc

To show the contents of a zip file:
unzip -l archive.zip

To extract all files in a zip file into the current directory:
unzip archive.zip

If you only want to extract a single file from a zip archive:
unzip archive.zip filename

You can also specify multiple file names to extract. If you created an archive of the /etc directory in the example above and now want to extract the files hostname and hosts into the current directory:
unzip archive.zip etc/hostname etc/hosts

How to use zip on the command line
Share this