Home Linux System Administration How To Zip Multiple Files on Linux

How To Zip Multiple Files on Linux

by schkn

ZIP is by far one of the most popular archive file format among system administrators.

Used in order to save space on Linux filesystems, it can be used in order to zip multiple files on Linux easily.

In this tutorial, we are going to see how can easily zip multiple files on Linux using the zip command.

Prerequisites

In order to zip multiple files on Linux, you need to have zip installed.

If the zip command is not found on your system, make sure to install it using APT or YUM

$ sudo apt-get install zip

$ sudo yum install zip

Zip Multiple Files on Linux

In order to zip multiple files using the zip command, you can simply append all your filenames.

$ zip archive.zip file1 file2 file3

adding: file1 (stored 0%)
adding: file2 (stored 0%)
adding: file3 (stored 0%)

Alternatively, you can use a wildcard if you are able to group your files by extension.

$ zip archive.zip *.txt

adding: file.txt (stored 0%)
adding: license.txt (stored 0%)

$ zip archive.zip *.iso

adding: debian-10.iso (stored 0%)
adding: centos-8.iso (stored 0%)

Zip Multiple Directories on Linux

Similarly, you can zip multiple directories by simply appending the directory names to your command.

$ zip archive.zip directory1 directory2

adding: directory1/ (stored 0%)
adding: directory2/ (stored 0%)

Conclusion

In this tutorial, you learnt how you can easily zip multiple files on Linux using the zip command.

You also learnt that wildcards can be used and that you can zip multiple directories similarly.

If you are interested in Linux System Administration, we have a complete section dedicated to it on the website, so make sure to have a look.

You may also like

4 comments

aaa February 4, 2021 - 4:21 pm

use -r

Reply
ES March 14, 2021 - 4:27 pm

^ Otherwise you’ll only copy the directory, not the contents.

Reply
Nour April 21, 2021 - 8:14 am

Thanks for the great article.

There’s a typo in “Prerequisites” section.
In Redhat compatible distros, it’s `sudo yum install zip` not `sudo apt-get install yum`

Reply
schkn April 25, 2021 - 9:52 am

Many thanks, it is fixed!

Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.