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
Difficulty Easy (rss)
Root privileges No
Requirements zip utility
Time N/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.

ADVERTISEMENTS

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.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
27 comments… add one
  • bryan Jan 9, 2009 @ 2:01

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

    • Fauzi Jul 2, 2015 @ 23:18

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

  • Luuk Jan 16, 2009 @ 10:46

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

  • Dhawal Jun 10, 2009 @ 8:22

    Thanks….This is what i was looking for.

  • Vishwajeet Singh Feb 13, 2010 @ 7:46

    It helped me as well thanks :)

  • Bojan Sukalo May 6, 2010 @ 9:58

    It’s good to be reminded!

    Thank You!

  • VinceHardsmash Sep 17, 2010 @ 18:52

    Thanks! It helped bunches!

  • Sunil Jan 28, 2011 @ 3:58

    Thanks a ton.

  • zippa Mar 14, 2011 @ 10:33

    man zip ?

  • sushil Apr 28, 2011 @ 12:27

    thanks !

  • bob Jun 20, 2011 @ 16:08

    lol just do right click compress

    • JJJollyjim Jul 28, 2011 @ 23:33

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

    • smart Sep 12, 2012 @ 16:58

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

  • Ahmad Fikrizaman Jan 23, 2012 @ 19:12

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

  • Ahmed Adel Feb 29, 2012 @ 0:18

    Very useful
    Thank you

  • hoze Apr 6, 2012 @ 11:29

    Great. Thx for help. Just what I need!

  • Sam Oct 13, 2012 @ 4:13

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

  • Sukumar Oct 17, 2012 @ 10:24

    Wonderful. Saved my time.

  • joneskind Jan 14, 2013 @ 1:19

    Hi,

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

  • prafulla Jul 11, 2013 @ 8:02

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

    • hello Oct 1, 2017 @ 16:27

      Yes, you can add “-0” to not compress files, but only store.
      You can use -0, -1, -2, -3.. etc up to -9
      ( -9 nine compress better, -0 compress faster )

  • yash Aug 16, 2014 @ 7:33

    thanks! It helped!

  • Abdul Basit Nawab Apr 14, 2015 @ 13:09

    Yeah! work like a charm.

  • multiple_uses Jul 16, 2015 @ 22:13

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

  • Kiara May 19, 2016 @ 17:53

    thank you!!! :)

  • Ben Aug 3, 2016 @ 21:34

    Thanks a lot!

  • Rehan Gillani Nov 21, 2016 @ 17:23

    A Quick Tip… But Really Very Helpful.
    Thanks Buddy! :)

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.