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
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.
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.