How Zip and Unzip Files via Commandline in Linux

How Zip and Unzip Files via Linux Commandline

by Dan

To Zip and Unzip files in various Linux Distros like Ubuntu,Fedora and Mint,you need to Install ZIp and Unzip software separately.

Install Zip Software

To Install Zip/Unzip software’s on Debian based websites such as Ubuntu

$ apt-get install zip
$ apt-get install unzip

For Red Hat based Distros such as Fedora use the following command

$ yum install zip
$ yum install unzip

To Zip the files in current user’s Documents folder

$  zip ~/Documents/test/*

where is the file name of the zip archive  and it will be zipped in your current folder

Zipping and UnZipping

To Zip the files and Folders recursively

$  zip -r ~/Documents/test/

To zip the files in current directory

$ zip myfile *

Where myfile is the name of your Zip file

To recursively zip files and Directories in current Folder

$ zip -r myfile *

To unzip the file

$ unzip

where is the name of the Zip file

To see the contents of a Zip file without Unzipping

$ unzip -v

To Validate a Zip file to check for Error

$ unzip -t

To create a Password for Zip files

there are two method to do this,the second method is best as it does not displays the password

Method 1 :

$zip -P yourpassword ~/Documents/test/*

Method 2 :

$ zip -e ~/Documents/test/*
Enter password:
Verify password:

As you can see the method two prompts for a password while zipping the files.

To Unzip the Password protected file use same command used for Unzipping the normal zip files,It will prompt for the zip password while unzipping the password protected zip files.

To Unzip the files to different Directory

$ unzip -d /tmp

In the above command you are unzipping the zip file called “” to your temporary folder called “/tmp”

To Zip files by according to Compression Level

There are 10 levels of compression levels from level 0-9.Level 0 is the fastest but doesnt compress files just stores the files in zip,while Level 9 is the slowest but compresses files to its minimum size.

To Zip files to level 0

$ zip -0 ~/Documents/test/*

To Zip files to level 9

$ zip -9 ~/Documents/test/*

To Extract specific file from a Zip

You can use the following command to unzip particular file from the Zip file

$ unzip tux.png

the above command extracts the image file called “tux.png” from “

Thats a big list I hope,If you like to share some commands please comment back

Related Posts