≡ Menu

Zipping A Directory In Linux Terminal

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.


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/
$ 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.

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 23 comments… add one }

  • bryan January 9, 2009, 2:01 am

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

    • Fauzi July 2, 2015, 11:18 pm

      I forgot it as well, although my search engine wasn’t google. It was duckduckgo, but still the first result though. :’)

  • Luuk January 16, 2009, 10:46 am

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

  • Dhawal June 10, 2009, 8:22 am

    Thanks….This is what i was looking for.

  • Vishwajeet Singh February 13, 2010, 7:46 am

    It helped me as well thanks :)

  • Bojan Sukalo May 6, 2010, 9:58 am

    It’s good to be reminded!

    Thank You!

  • VinceHardsmash September 17, 2010, 6:52 pm

    Thanks! It helped bunches!

  • Sunil January 28, 2011, 3:58 am

    Thanks a ton.

  • zippa March 14, 2011, 10:33 am

    man zip ?

  • sushil April 28, 2011, 12:27 pm

    thanks !

  • bob June 20, 2011, 4:08 pm

    lol just do right click compress

    • JJJollyjim July 28, 2011, 11:33 pm

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

    • smart September 12, 2012, 4:58 pm

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

  • Ahmad Fikrizaman January 23, 2012, 7:12 pm

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

  • Ahmed Adel February 29, 2012, 12:18 am

    Very useful
    Thank you

  • hoze April 6, 2012, 11:29 am

    Great. Thx for help. Just what I need!

  • Sam October 13, 2012, 4:13 am

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

  • Sukumar October 17, 2012, 10:24 am

    Wonderful. Saved my time.

  • joneskind January 14, 2013, 1:19 am


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

  • prafulla July 11, 2013, 8:02 am

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

  • yash August 16, 2014, 7:33 am

    thanks! It helped!

  • Abdul Basit Nawab April 14, 2015, 1:09 pm

    Yeah! work like a charm.

  • multiple_uses July 16, 2015, 10:13 pm

    This is greeeeeeeeeeeeat!!! Thanks a loooooooooooooooooot!!! :D

Leave a Comment