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 level Easy
Root privileges No
Requirements zip utility
Est. reading time 1 minutes
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.
Advertisement

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.

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

27 comments… add one
  • 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. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.