Zipping A Directory In Linux Terminal

last updated in Categories , , , , ,

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.
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 file1 file2 
zip dir1 
zip -option dir1

To zip directory called pics in your home directory (/home/you/pics), type the following command:
$ zip -r /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 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

zip -R "*.c"

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

27 comment

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

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

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

    1. 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 )

    Still, have a question? Get help on our forum!