23

I don't think that I'm the only one with this problem, but unfortunately I wasn't able to find the proper answer between previously asked questions.

It is a very common procedure on torrent sites where the content is split in many small archives. Sometimes, those small indexed zip archives are containing another rar archives inside.

So, my question is: how to you handle this problem? How to you recursively unpack those files?

Braiam
  • 67,791
  • 32
  • 179
  • 269
rda
  • 437

4 Answers4

31

To do so, just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

unzip '*.zip'

Also you can right click on the first file in the group, and choose Extract here, and that will also all the files in that group.

Mitch
  • 107,631
5

To unzip multiple files using a loop -

for z in *.zip; do unzip "$z"; done
  • @DavidFoerster The two methods are essentially the same. *.zip provides all the possible files ending with a zip extension which the loop unzips one by one. This is also why @Mitch has included single quotes in his answer to make it '*.zip', so that the the shell will not recognize it as a wild card character. – Rohith Madhavan Dec 23 '14 at 17:08
  • 2
    This is actually a better method since you can specify a file name list instead of saying "all files in the directory". I.E. you want to extract a specific list of zip files one after the other in order, you could do, "for z in X Y Z T G; do unzip -o "$z.zip"; done" and it would do it in that order. This is the better answer imho. – John Hamilton Aug 23 '17 at 08:29
  • Okay, but what is unzip's problem? If I do for z in find **/subdir/*.zip; unzip -l "$z"; done it will list the files in the folders but it will also give me this error cannot find or open find, find.zip or find.ZIP.. But that's not in the output of find. – grofte Mar 29 '21 at 18:08
1

How to unzip multiple files at once

...using parallel operations (one CPU core per process, with as many processes as you have cores), into output directories with the same names as the zip files:

This might look complicated, but it's beautiful and fast. It will unzip all top-level *.zip files in your current directory into folders of the same name as the zip file:

# Install `unar` (un-archive)
sudo apt update
sudo apt install unar

Unzip all files

time find . -maxdepth 1 -type f -iname "*.zip" -print0 | xargs -0 -I{} -n 1 -P $(nproc) unar -f {}

  • unar is used instead of unzip because unar automatically puts the extracted output into a folder with the same name as the .zip file.
  • If you'd like to extract *.zip files in lower levels too, remove the -maxdepth 1 option.

References

  1. Unix & Linux: Unzip to a folder with the same name as the file (without the .zip extension)
  2. My answer on how to use xargs

See also

  1. My longer answer, based on the work above, where I extract one or many password-protected files in parallel using find, xargs, and unar -p my_password path/to/myfile.zip.
0

CTRL+ALT+T to open up a terminal

for f in $(ls | egrep zip); do
  unzip $f -vd UnzippedDirectory
done

This basically loops through all the zips you got in your current directory, and unzips each of them verbose (hence the -v flag) into a directory (-d flag)