How to zip and unzip files in Linux#

To create ".zip" files in Linux, you use the zip command. To unzip ".zip" files, you use the unzip command.

Here are some common uses of the zip and unzip commands in Linux.

To zip a single file:

$ zip myfile.zip myfile.txt

To create a zip archive of several files:

$ zip myfiles.zip file1.txt photo.jpg script.js

To zip up a whole directory named downloads:

$ zip -r downloads.zip downloads

To create a zip archive of files and directories:

$ zip -r myfiles.zip file1.txt photo.jpg script.js downloads

To check if a zipped archive is fine or not:

$ unzip -tq downloads.zip

To unzip a zip archive:

$ unzip downloads.zip

To see the contents of a zip archive:

$ unzip -l downloads.zip

To extract a file from a zip archive:

$ unzip downloads.zip photo23.jpg

To unarchive a zip archive to a specific location:

$ unzip downloads.zip new_downloads

Exercise#

  • When is the tar command used?
  • What are the alternatives to zip and unzip commands?

References#