Linux zip many files

How do I zip up multiple files on command line?

Forgive this most basic question, but I couldn’t find a direct answer or simple example on stack exchange. Let’s say I have a folder of files that I would like to compress into one zip file that I can share with my terrible Windows friends (otherwise I’d just use tar and be done with it). It looks like this:

. ├── file1.txt ├── file2.txt ├── file3.txt ├── file.jpg └── test.jpg 

-@ file lists. If a file list is specified as -@ [Not on MacOS], zip takes the list of input files from standard input instead of from the command line. For example,

cat zip.lst file1.txt file2.txt file3.txt file.jpg test.jpg 

But it didn’t do anything except create a blank line on the console. And I can keep pushing Enter and it just keeps making more blank lines without seemingly executing the command. After some searching, I realized that I needed to terminate input by pressing Ctrl + D But now I get this error:

 zip warning: missing end signature--probably not a zip file (did you zip warning: remember to use binary mode when you transferred it?) zip warning: (if you are trying to read a damaged archive try -F) zip error: Zip file structure invalid (zip.lst) 

What!? How is my simple list not a «valid file structure»? Back to the manual for more information, and I take a closer look at:

So I try it without -@ , and that at least processes it right away without having to press Ctrl + D but I’m left with the same error. Luckily, I found a comment on an answer to a nearly unrelated question that led me to realize that I needed to explicitly name the zip file. This error’d because by default it was trying to create a zip file called zip.lst . But since that’s the name of my list, one might think that it would simply overwrite it, but no, it was in fact trying to update it. And since the list obviously isn’t a zip file, we get the invalid file structure error, and now it’s clear why it said «probably not a zip file.» So then I tried:

zip files.zip zip.lst adding: zip.lst (deflated 35%) 
. ├── file1.txt ├── file2.txt ├── file3.txt ├── file.jpg ├── files.zip ├── test.jpg └── zip.lst 
unzip -l files.zip Archive: files.zip Length Date Time Name --------- ---------- ----- ---- 48 2016-05-24 15:30 zip.lst --------- ------- 48 1 file 

No! Well, actually that makes sense from standard usage because it just zipped up the one list file I gave it. Finally I tried again with -@ but got the same result. What am I doing wrong? BTW, I know I can use the GUI and do it with my mouse, but I need to script this, and in general I’m faster on the CLI when I know what I’m doing.

Читайте также:  Hcxpcapngtool install kali linux

Источник

Linux Zip Multiple Files

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.

Web development, programming languages, Software testing & others

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.

2. Removal of a file from zip.

3. Updating or including a file in a zip.

4. Removal of original files after zip.

5. Recursive zip of folders.

6. Exclusion of a file while zipping.

7. Verbose mode during zip.

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.
  • 7: 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.
Читайте также:  Terminal hidden files linux

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.

zip -sf eduCBA.zip zip -d eduCBA.zip file3.txt zip -sf eduCBA.zip

Linux Zip Multiple Files 1

Example #2

Updating or including a file in a zip.

zip -sf eduCBA.zip zip -u eduCBA.zip fileInclude.txt zip -sf eduCBA.zip

Linux Zip Multiple Files 2

Example #3

Removal of original files after zip.

ls -lrt zip -m eduCBA.zip *.txt ls -lrt

Removal of original

Here we see that all the txt files are deleted after they are zipped.

Example #4

zip -r eduCBA.zip zipDemo/ ls *.zip -lrt zip -sf eduCBA.zip

Recursive

Example #5

Exclusion of a file while zipping.

zip eduCBAexclude.zip *.txt -x file3.txt zip -sf eduCBAexclude.zip

Exclusion

Here we see that all the files are included in the zip, except the file3.txt.

Example #6

zip -v eduCBAverbose.zip *.txt

Linux Zip Multiple Files 6

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.

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.

502+ Hours of HD Videos
54 Courses
4 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5

Читайте также:  Gcc unknown linux gnu

57+ Hours of HD Videos
15 Courses
9 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5

Источник

How Do I Zip All Files In A Directory In Linux?

Zip archives refer to container archives that contain one or more compressed files and directories. Zip files are cross-platform, allowing you to create zip archives in Windows, Linux, and macOS using various utilities. In addition, zip archive files take less space, making them easier to transfer and store.

In Linux, we use the zip archive utility to create zip archives. Throughout this tutorial, we will focus on how to go about creating zip archives in Linux using the zip utility.

Install Zip

Depending on your Linux distribution, you will need to install the zip utility. Since all Linux distributions support it, you can use the package manager to install it.

For Debian/Ubuntu

On Debian, use the command:

For REHL/CentOS

On CentOS and REHL family, use the command:

The Zip Command

The zip command is simple to use. The general syntax for the command is:

To create a zip archive of more than one file, pass them in a list (separated by space) after the zip filename. It is also good to ensure you have to write permissions in the directory you are creating the zip file.

How to Zip Files In Linux

We can zip files in a directory as:

The command above displays the name of the file added to the archive and the compression method.

Zip utility automatically adds a .zip extension to the archive filename—if not explicitly specified.

How to Compress Zip Directories In Linux

You can compress directories and the corresponding sub-directories by using the -r flag. The -r flag will tell zip to traverse the entire directory recursively.

For example, consider the /var/log directory. To create an archive of all the files and directories, we use the command:

To suppress the output from the compression process, use the -q for quiet mode. The command creates a zip archive of the specified files with no output.

How to Zip all Files in a Directory In Linux

What if you want to zip all files in a directory? In that case, we use wildcard expressions to do this.

The above command adds all the files and directories in the specified path and adds them to the zip archive.

How to Zip All Files, Including Hidden Files

To add even hidden files to a zip archive, use the wildcard (.* *). The command for that is:

Conclusion

As shown in this tutorial, Linux allows you to create zip archives. You can use any archive utility such as WinRar, 7zip, unzip; to unarchive the files.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list

Источник

Оцените статью
Adblock
detector