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.

How To: Extract An .rar File

Today, we’re going to learn how to extract an .rar file in Linux. You don’t see .rar files all that often with Linux, but sometimes they crop up. Today’s article will explain how to extract them.

You may recall .rar files from your Windows days, assuming you have a history with Windows – as many of us Linux users do. You’d probably be most familiar with the application known as ‘WinRAR‘. 

While the application is specifically for Windows (there’s a text-based WinRAR for Linux, perhaps a subject for another article), it produces files compressed with the .rar format. The .rar compression is much like any other compression, from .tar.gz to .zip. At some point, you may be faced with opening one while you’re using Linux.

Just because the files are often made with WinRAR doesn’t mean the files will only be opened in Windows. Once in a while, you’ll find something you need that’s in .rar format and you’re using Linux. Well, fear not, you can extract an .rar file easily enough. It’s just a simple terminal command away and you should be all set. While not a skill you’ll need often, it’s one you’ll maybe need and now is a good enough time to learn how.

Extract An .RAR File:

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.

Once you have the terminal open, you’ll need to install an application called ‘unrar’. If you’re using a major distro, it’s likely in your repository – though maybe under the name of ‘unrar-nonfree’. Search your repositories and you’ll find it.

If you’re using Debian/Ubuntu/similar then it’s easy enough – it’s called ‘unrar’ and you install it with: