How to zip folder and unzip zip file in Ubuntu

In this tutorial we will see how zip/unzip files and folders in Ubuntu Linux. Zip is a very popular compression format used mainly in Windows. To zip files and folder in Ubuntu we need to install zip package. To unzip zip file we need to install unzip command. Both packages are installed by default on Ubuntu desktop version, but not in the Ubuntu server.

How to zip folder and unzip zip file in Ubuntu

To install zip and unzip on Ubuntu, Run:

sudo apt-get update
sudo apt-get install zip unzip

Zipping Files and Folders with zip

The following syntax creates a zip archive in Ubuntu terminal:

zip archive_name.zip file1 file2 file3

AS you can see we can archive and compress one or more files together using the zip command.

If you zip a directory, remember to use the -r flag to zip all the files within it recursively:

zip -r www.zip /var/www

To create password protected zip files, use the -e or --encrypt option:

zip -r -e www.zip www

To create a zip file in GUI, right click on the file and select compress, then select archive format and click create.

Zipping Files and Folders with zip

Unzipping Zipped Files with unzip

We can unzip zipped files using unzip command, from the Ubuntu terminal. Enter unzip followed by the name of the file to unzip:

unzip file.zip

The unzip command will extract the file(s) to the current working directory. To extract zip file to a different location, use the -d flag:

unzip -d /tmp/ www.zip

unzip will extract the file(s) to the /tmp directory.

If the zip file is password protected, you will be prompted to enter password, optionally you could provide the password using the -P (upper case p) option:

unzip -P 'password' www.zip

The -l flag lists the files in an archive without extracting them:

unzip -l www.zip

To extract zip file from the Ubuntu GUI, right click on file and select Extract Here to unzip to the current directory or Extract To if you want to unzip the file to a different location.