Tuesday, June 24, 2008

How to zip and unzip a file or folder under linux

Perhaps you have downloaded a file from internet with .zip extension. Or
You want to send a list of files to your friends. Or
your folder /file size is too large that you want to reduced.
In all of these cases you have to be familiar with the zip and unzip command.

Zip is used to compress a file or folder and unzip is used to decompress/extract.


On windows it is quitely easy to do it. Windows by default have winzip program which is used to do the task. You can manually in windows can install winrar software and do the same task more efficiently.

On linux there is command line tool and also various ways to do it. The command line tool zip and unzip is used to do the task.

If you don't have any unzip tool then yet you can do unzip. To do it just enter to the .zip extention file and copy the contents inside it to another location outside zip file.


The zip and unzip tool is by default not installed on linuz system. You have to install it manually.

If you are in debian linux distribution then as a root user install it as,

# apt-get install zip
# apt-get install unzip


If you are Red Hat Linux or Fedora Core user then use yum command to install zip and unzip program like,

# yum install zip
# yum install unzip


Now you have both zip and unzip utility by which you can do the task.

Here is some example of zipping and unzipping process in linux.

Example zip 1:
-----------------------------------

To make archive named as myzip.zip with all the files in the current directory issue,
$ zip myzip *
The archive name will be automatically to .zip extension. So no need to give extension.

Example zip 2:
-------------------------------------------

To make a zip file of the entire directory and subdirectory under it issue,
$ zip -r myzip *

To make zip of all files under /root/Image issue ,
zip myzip /root/Image/*
which all make archive named myzip.zip and save the archive in current directory. To save the archive in another location like /home/Arju issue,
zip /home/Arju/myzip /root/Image/*

Example unzip
------------------------------------------------

1)To list the available files with size inside zip archive issue,
unzip -l myzip.zip

2)To extract all files into the /tmp directory:
$ unzip myzip.zip -d /tmp

3)You can test whether zip file is ok or not and then printing summary by,
$ unzip -tq myzip.zip

4)To unzip all files in the current directory use,
$ unzip /home/Arju/myzip.zip

1 comment: