FactorPad
Build a Better Process

Linux zip Command Summary with Examples

Linux zip allows you to compress and archive files.
  1. Purpose - Learn what zip is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with zip.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 24, 2021
In this tutorial on Linux zip, 72 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / zip-command.html


An ad-free and cookie-free website.


Examples of the Linux zip Command

Beginner

Learn to compress and archive files at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux zip Command Summary with Examples (3:50)

Video Script

The Command and Why You Need It

Our seventy-second word, or command to memorize is zip from our category Files.

zip allows you to compress and archive files.

Common Linux zip Options
-options description
-h, --help Print help screen
-r, --recursive Include directories and files recursively

Recall from the last four videos, we've been evaluating ways to compress files and now we'll shift to archiving, or packaging both files and directories, while compressing at the same time.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The zip command has over 30 options and the arguments include the output file, in .zip format and the input files and directories.

Like most commands, help is available with double-dash --help, and -r is the recursive option required to include directories and files.

So why is zip an important command? Well, in order to share .zip files, a standard for many Microsoft Windows and Mac users, you need to know how to pack and unpack them. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. First, let's use mkdir to create a directory called video72 and redirect to it, the long but helpful man pages of the command zip to video72a.txt and unzip to video72b.txt.

$ mkdir video72 $ man zip > video72/video72a.txt; man unzip > video72/video72b.txt

And then let's to an ls of that directory to make sure the files are in there.

$ ls video72 video72a.txt video72b.txt

Next, let's zip the directory using zip -r, the destination video72.zip and the directory video72.

$ zip -r video72.zip video72 adding: video72/ (stored 0%) adding: video72/video72a.txt (deflated 69%) adding: video72/video72b.txt (deflated 65%)

And see, the three actions, followed by ls -og video72*.

$ ls -og video72* -rw-r--r-- 1 48385 Nov 6 19:24 video72.zip video72: total 144 -rw-r--r-- 1 93424 Nov 6 19:23 video72a.txt -rw-r--r-- 1 53014 Nov 6 19:23 video72b.txt

And it shows the zip and contents.

And last, let's decompress using unzip video72.zip.

$ unzip video72.zip Archive: video72.zip replace video72/video72a.txt? [y] yes, [n] no, [A]ll, [N]one, [r]ename: _

And then it asks for multiple options here so hit capital A for All.

$ unzip video72.zip Archive: video72.zip replace video72/video72a.txt? [y] yes, [n] no, [A]ll, [N]one, [r]ename: A inflating video72/video72a.txt inflating video72/video72b.txt

Then ls the video72 directory to see the two files.

$ ls video72 video72a.txt video72b.txt

A Final Tip

Okay now you know how to use zip. And you know the syntax for commands, options and arguments.

One last tip about the zip command. So now that you have two helpful man pages, please review them because they include many helpful examples for this very versatile program.

Okay, thanks for visiting today. I hope this was a helpful introduction to the zip command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

Please, if you found value here, return the favor, tell a friend, subscribe, follow, or give. It all helps to keep the free content flowing.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / zip-command.html


linux zip command
zip linux
unzip linux
linux unzip
linux zip folder
zip folder linux
linux zip file
zip file
zip command
linux zip directory
zip file linux
unzip zip
unzip command
extract zip linux
zip command examples
zip command tutorial
extract zip file
free zip file opener

A newly-updated free resource. Connect and refer a friend today.