Zipping A Directory In Linux Terminal

by on October 31, 2007 · 19 comments· LAST UPDATED September 12, 2012

in , ,

How do I zip files in Linux so that I cam email them to my friend? How do I zip files on server using the shell prompt?

zip is a compression and file packaging utility for Unix, Linux, VMS, MSDOS, OS/2, Windows NT, Minix, Atari and Macintosh, Amiga and Acorn RISC and many other operating systems.

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Requirementszip utility
Estimated completion timeN/A

This utility is installed by default on most Linux computers and servers. The program is useful for packaging a set of files for distribution; for archiving files; and for saving disk space by temporarily compressing unused files or directories.

Syntax

zip's syntax is:

 
zip file.zip file1 file2
zip file.zip dir1
zip -option file.zip dir1
 

To zip directory called pics in your home directory (/home/you/pics), type the following command:
$ zip -r myvacationpics.zip /home/you/pics/
or
$ zip -r myvacationpics /home/you/pics/
The -r option recurse into directories (all files and directories inside pics) to produced zip file called myvacationpics.zip. You can travel the directory structure recursively starting at the current directory. In this example, all the files matching *.c in the tree starting at the current directory are stored into a zip archive named mycode.zip.

 
zip -R mycode.zip "*.c"
 

Please note that *.c will match file.c, dir1/file.c and dir1/dir2/.c and so on.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 19 comments… read them below or add one }

1 bryan January 9, 2009 at 2:01 am

I forgot how to do this. First result on google, exactly what I needed. Thanks.

Reply

2 Luuk January 16, 2009 at 10:46 am

Same for me, very useful! Also simple things can be forgotten. Thank you!

Reply

3 Dhawal June 10, 2009 at 8:22 am

Thanks….This is what i was looking for.

Reply

4 Vishwajeet Singh February 13, 2010 at 7:46 am

It helped me as well thanks :)

Reply

5 Bojan Sukalo May 6, 2010 at 9:58 am

It’s good to be reminded!

Thank You!

Reply

6 VinceHardsmash September 17, 2010 at 6:52 pm

Thanks! It helped bunches!

Reply

7 Sunil January 28, 2011 at 3:58 am

Thanks a ton.

Reply

8 zippa March 14, 2011 at 10:33 am

man zip ?

Reply

9 sushil April 28, 2011 at 12:27 pm

thanks !

Reply

10 bob June 20, 2011 at 4:08 pm

lol just do right click compress

Reply

11 JJJollyjim July 28, 2011 at 11:33 pm

I need to zip something on a linux server WITH NO GUI, and so this tutorial was very helpful. Thanks

Reply

12 smart September 12, 2012 at 4:58 pm

what a smart ass.. this is a server we are talking about without a GUI

Reply

13 Ahmad Fikrizaman January 23, 2012 at 7:12 pm

thanks.. can`t understand zip –help.. lol..

Reply

14 Ahmed Adel February 29, 2012 at 12:18 am

Very useful
Thank you

Reply

15 hoze April 6, 2012 at 11:29 am

Great. Thx for help. Just what I need!

Reply

16 Sam October 13, 2012 at 4:13 am

hay it is nice tutorial. But i want to know how should i un-zip the file

Reply

17 Sukumar October 17, 2012 at 10:24 am

Wonderful. Saved my time.

Reply

18 joneskind January 14, 2013 at 1:19 am

Hi,

Is there a command line to set the zip compression ? As a lot of archiver do ?
Thanks !

Reply

19 prafulla July 11, 2013 at 8:02 am

Hi,
Thanks a lot it worked for me as well, while its bit time consumming..
any other way to process it bit faster???

Reply

Leave a Comment

Tagged as: , , , , , ,

Previous Faq:

Next Faq: