Make a zip archive from the command line

There's only really one universally interchangeable archiving and compression format that works across all major platforms, and that's the Zip format. Like it or not, that's what you are stuck with using if you need to exchange files with other operating systems.

Creating a Zip archive using a GUI is usually a very simple process which involves right-clicking a group of files or a folder and choosing the relevant option.

From a command line, it's a little more complex, but it's still very achievable and it is always useful to know how to do it from the command line.

Unzipping is easy, simply get yourself a suitable Zip file, and do the following:

$ unzip

You will see some messages about deflating the files and then you should end up with the archive decompressed to your current working directory.

Compressing is slightly more complex and works something like this:

$ zip -b . stuff *

Let's take a look at the anatomy of that command in more detail. First of all, you run zip. Pretty simple, right?

The -b . switch indicates the directory in which you want the Zip archive file to be created. In this example, I've said . (i.e. the current working directory), but you can specify any directory which will be where your .zip file ends up.

stuff in this example is the name of the archive. Your filename will be this, with .zip added to the end.

Finally, * indicates that I want to zip all the files that are in this directory. That is probably the easiest way to work as you can just set up a directory containing your files, cd to it and use the * wildcard.

Of course, it is possible to be more advanced, so if you want to take your command line zip-fu a little further, then go ahead and read the man page.

Just remember - Zip files don't support Unix permissions, ownership or anything special like that. If you need to preserve that sort of information, you'll need to use tar instead!

Avatar for peter Peter Upfold -

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Make a zip archive from the command line

Home » Articles » Make a zip archive from the command line