Linux zip files

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

Today we'll be looking at how to zip up one or multiple files on Linux systems. Zipping files can come in super handy when dealing with multiple files or backups that need to be transferred or moved.
In my case, this situation occurred because I wanted to email attach multiple log files.
Let's first look at the command itself.
zip options zip_name files
Where this works as follows:
zip: The Linux command to zip thingsoptions: We can pass in arguments for the end zip resultszip_name: The output name, without the .zip partfiles: One or more files comma separatedTo show you the most simple zip command for one file, we could do this.
zip archive test.txt
This will create an archive.zip in that folder containing the test.txt file.
zip on Ubuntu or CentosTo install the zip command on Ubuntu or Debian systems, you can run the following command.
sudo apt install zip
For CentOS and Fedora systems, you can use Yum.
sudo yum install zip
To add multiple files, we can specify them with a space between like this.
zip archive test.txt test2.txt test3.txt
However, in most cases, you want to zip a whole folder and its contents, right?
To achieve this, we can pass the -r option (Recursive).
zip -r archive my_directory
This will take all the files inside my_directory and zip them into one archive.
As we did above, we can still add separate files in the zip by passing them along.
zip -r archive my_directory test.txt
So far, we have seen the -r option to add files in a folder recursively.
As you may know, there are multiple compressions levels for zip files. The default one is deflate. But we can also zip files using the bzip2 compression.
To use a different compression method, we can pass the -Z option.
zip -r -Z bzip2 archive my_directory
We can also specify the level of compression we want. This is passed with a number from 0-9. Where 0 is no compression and 9 the highest. The default compression is -6.
To use it:
zip -r -9 archive my_directory test.txt
Another cool option is to encrypt the zip. This means we put a password on it.
zip -r -e archive my_directory
This will prompt you for the password twice.
# Enter password:
# Verify password:
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter