Updated April 14, 2023
Introduction to Linux Zip Multiple Files
The following article provides an outline for Linux Zip Multiple Files. Zip multiple files are defined as a command or utility which enables users to compress and package multiple files together. Now, compression of files can be performed in various ways. The first one is reducing the file size and then package them for later steps. The other way of compression is not through size but maybe collating different files at a different location to a single location before packaging them. In order to perform compression, there is a compression ratio that is maintained to reduce the file size but not interfere with the quality. The utilities post zipping can be either from archiving, saving space temporarily for unused files or directories.
Syntax of Linux Zip Multiple Files
In Linux, there are a lot of utilities of zip available for users, and later in the article, take a dig at the working of zip multiple files command in Linux. The parallel and analogous command to zip is the tar command.
1. The main syntax.
Syntax:
zip [options] <name of zip file> <list of files to be zipped>
2. Removal of a file from zip.
Syntax:
zip -d <name of zip file> <list of files to be removed>
3. Updating or including a file in a zip.
Syntax:
zip -u <name of zip file> <list of files to be included>
4. Removal of original files after zip.
Syntax:
zip -m <name of zip file> <list of files to be removed>
5. Recursive zip of folders.
Syntax:
zip -r <name of zip file> <directory to be zipped>
6. Exclusion of a file while zipping.
Syntax:
zip -x <name of zip file> <list of files to be excluded>
7. Verbose mode during zip.
Syntax:
zip -v <name of zip file> <list of files>
How to Zip Multiple Files in Linux?
In recent times, there are a lot of frequently occurring situations that the files downloaded from the internet are too many in numbers, or data is widely and more importantly present in huge amount. And while this happens, sharing files amongst each other possess a challenge. This calls for an immediate answer to solve all these problems, and that is where zipping multiple files is so important in today’s world. Zipping of files has been a practice since a while ago, and the quest for using it even more is getting its share of interest.
Here we would look at the process of zipping multiple files in Linux. The process is very similar to the one we perform in windows if one is familiar with the process in windows. The only difference lies in the way we process the same. In Linux, we perform it through the command line interface and in windows, there are tools like Zip, 7Zip, etc., to perform the same utilities.
Now, let us look at different options in the command zip when it comes to the sipping of multiple files.
Given below are the options:
- d: This option is used for the deletion of a file in the zip.
- u: This option is used for updating or including a file in the zip.
- m: This option is used for the removal of the original file after the zip.
- x: This option is used for the exclusion of files in the zip.
- r: This option is used for recursive zip of folders.
- v: This option is used for verbose print during zip.
- dc: This option is used for displaying running counts of entries zipped.
- e: This option is used for encrypting a zip file.
- sf: This option is used for extraction of contents without actual extraction of zip.
- [0-9]: This option is used for moderating the level of compression during zip (0 being lowest and 9 being highest).
- y: This option is used for preserving the symbolic links during zip.
From the above options available, we see that different options take care of different utilities of zipping multiple files. While some of them are widely used, some of them are essential for the quick turnaround of things. For example, running an unzip function and then extracting the content takes more time, rather than just using the option of sf. One more important thing is that we should make sure of the compression level during the compression of large files. We can reach at the highest level of compression, i.e. 9, given the case that the user is ready to take the burnt of higher time for high compression. In case it is not that important, one can use the default, which is 6. There is a possibility of symbolic links being present in the zip, and as for preserving the same, the option y should be used. Zip of multiple files allows users to use different compression method and one of them being bzip2.
Examples of Linux Zip Multiple Files
Given below are the examples of Linux Zip Multiple Files:
Example #1
Removal of a file from zip.
Syntax:
zip -sf eduCBA.zip
zip -d eduCBA.zip file3.txt
zip -sf eduCBA.zip
Output:
Example #2
Updating or including a file in a zip.
Syntax:
zip -sf eduCBA.zip
zip -u eduCBA.zip fileInclude.txt
zip -sf eduCBA.zip
Output:
Example #3
Removal of original files after zip.
Syntax:
ls -lrt
zip -m eduCBA.zip *.txt
ls -lrt
Output:
Here we see that all the txt files are deleted after they are zipped.
Example #4
Code:
Recursive zip of folders.
Syntax:
zip -r eduCBA.zip zipDemo/
ls *.zip -lrt
zip -sf eduCBA.zip
Output:
Example #5
Exclusion of a file while zipping.
Syntax:
zip eduCBAexclude.zip *.txt -x file3.txt
zip -sf eduCBAexclude.zip
Output:
Here we see that all the files are included in the zip, except the file3.txt.
Example #6
Verbose mode during zip.
Syntax:
zip -v eduCBAverbose.zip *.txt
Output:
Conclusion
With the set of examples and explanation of the way of working for zip command, the usage and utilizes are even more clear for the readers, and now we leave it up to readers to experiment with other options which are not explained in the examples, so as not to exhaust the article.
Recommended Articles
We hope that this EDUCBA information on “Linux Zip Multiple Files” was beneficial to you. You can view EDUCBA’s recommended articles for more information.