Let’s Zip A Directory In The Linux Terminal

Today, we’re going to zip a directory in the Linux terminal. This isn’t a very complicated task, but it’s worth covering. It’s also not something you’re likely to do every day, but it’s bound to be useful to some of you. You’re eventually going to want to share a directory’s worth of files with someone!

Why zip a directory? This is Linux, we deal with .tar.gz!

Well, in the real world, you might just want to share files with other people. They’ll have no idea what to do with a .tar.gz file – but they’ll know exactly what to do with a .zip file.

More importantly, pretty much every operating system on the planet can open a .zip file. Even way back with the Amiga and Atari systems, you were able  to open .zip files.

As an added bonus, you probably already have the utility to compress files into .zip files and won’t need to install anything! So, you won’t need to install anything and you’ll be able to share the resulting files with pretty much anyone on the planet. What’s not to love?

Heck, you don’t even need to install an application on Windows or MacOS to open .zip files. As a quick test, I can even open them with a file management application on Android. I’m not sure if Android also deals with them by default or if it’s a function of the file manager. Still, you can open .zip files just fine on Android.

With all those great things, you might just as well learn how to zip a directory in the Linux terminal. I promise, it’s really easy.

Zip A Directory:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

Chances are very good that you won’t have to install ‘zip’ to get this to work. You can find out quickly enough by just typing:

That’ll likely tell you which zip and where it’s located. If not, you’ll need to install it from your default repositories. I expect very few people will need to do that.

Now to zip a directory…

You can also zip a directory recursively, by using the ‘r’ flag:

This is not to be confused with the R flag, which will recursively compress the files in the folder – but only those files that were specified, such as from this example command in the man page:

That’d take all the files in the current directory that ended in ‘.c’ and compress them into a file called foo. That’s not really what we’re after, nor is it what the article is about. Either way, while you’re exploring, be sure to check the man page. This is one of the biggest man pages you’ll likely come across and there are a ton of options beyond just simply letting you zip a directory.

Closure:

There you have it. You can now zip a directory – such as a directory of pictures to share with your loved ones who are still not using Linux. It’s not terribly difficult, but it’s a useful skill to have and you never know when you’ll want to share a bunch of files with other people.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Smash a button!
[Total: 3 Average: 5]

Unzip A .zip File In the Linux Terminal

Today’s article is going to tell you how to unzip a .zip file in the Linux terminal. It shouldn’t be too complex, nor will it take a great deal of time to learn how to unzip a file.

In the Linux world, we don’t really see the .zip files all that often. We have other ways to compress files, but .zip is still there and you’ll sometimes come across them in your travels.

If you’re unaware, the .zip form of data-compression is actually a ratified standard. The format has been around since the late 80s and is one of the compression methods that supports loss-less compression. There are all sorts of compression formats and methods, but .zip has been around since forever and will probably exist long into the future.

If you want to unzip a .zip in a GUI, I’d say that you need look no further than PeaZip. It’s easy enough to compile from source, or you can find pre-built PeaZip packages for most distros. This article, on the other hand, is how to unzip a zip in the Linux terminal.

It’s not all that daunting and should be a pretty easy article for even a beginner to follow. Though, I suppose, any well-written article should be easy enough for a beginner to follow. Were I something other than a basic keyboard smasher, I’d probably be able to do that!

Read: Decompress a .tar.gz in the terminal

Unzip A .zip:

The headline clearly mentions doing this in the terminal, so you’re going to need an open terminal to continue. That’s relatively simple. Just press CTRL + ALT + T and your default terminal should open.

With your now-open terminal, let’s first make sure you have the ability to unzip a .zip file. To do that, let’s use:

That should return something akin to:

If you do not get a result, you’ll need to install unzip from your system’s repositories. Trust me, it’s in there – unless you’re using a really, really basic distro.

Assuming you get results indicating that you have unzip, it’s actually easy to unzip a .zip in the Linux terminal. You just navigate to the correct directory and run:

Which, I suppose, is mostly all you’re going to need. I should also mention that when you’re attempting to run this command, you can generally type the first few letters of the file name, and then press TAB to auto-complete the file name, saving you some typing time and just generally making the whole thing easier.

Obviously, there’s more to the unzip command. You can check the man unzip page, but the more useful flags will get covered here. Seriously, check the man page. The command is absurdly complex, with tons of options for obscure uses.

For example, to unzip a .zip to a different directory, you just use the -d flag, like so:

If you need to enter the password, you can just use:

When you want to list the files without decompressing them, you just use the -l flag, like this:

If you want to test the ,zip file to see if it’s corrupted, you can use the -t flag.

Normally, it’ll extract the files and overwrite the existing files (if any). You can avoid that with -n flag:

When you unzip a .zip, you will find out that it happily creates new directories. You can avoid that with the -j flag, like this:

Do read the man page! There’s a zillion options.

Closure:

Seriously, read the man page. Learn how to unzip a .zip file – and then all the many, many options included. Of all the man pages out there, this one is one of the most complex ’cause this one little application has a ton of options. Even if you don’t intend to learn it all, read the man page!

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Smash a button!
[Total: 6 Average: 5]
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.
Zoom to top!