FactorPad
Faster Learning Tutorials

Linux zip command summary with examples

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.
Paul Alan Davis, CFA, November 6, 2016
Updated: August 5, 2018
In this tutorial, 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 Next

~/ home  / tech  / linux essentials  / zip command


The Linux zip command

Beginner

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

Video Tutorial

Linux zip command summary with examples (3:50)

Videos can also be accessed from the YouTube Playlist.

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.

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?

To be notified of new video content, subscribe to the YouTube Channel here.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the xz command, hit Back.
  • For one more tutorial on file compression and the important tar command, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / zip command



 
 
Keywords:
linux zip command
zip linux
zip file
unzip zip file
compress files
compress directories
decompress files
decompress directories
open zip
linux unzip
extract zip
unzip files
zip folder
unzip directory
unzip command
zip example
file compression
zip command examples
zip command tutorial
extract zip file
free zip file opener