22

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
  • 66,947
  • 30
  • 177
  • 264
rda
  • 427
  • 1
  • 5
  • 11
  • 2
    Could you give an example? – ztik Dec 23 '14 at 11:38
  • Are you looking for a manual or a completely automated solution? – David Foerster Dec 23 '14 at 13:48
  • just a note, normally when you find that kind of torrents it about illegal software/movies, and you'll never actually get to the end of those .rar/.zip files because it's fake. – Jeggy Dec 23 '14 at 13:51
  • For password-protected files, see here: [Stack Overflow: unzip password protected zip in unix](https://stackoverflow.com/q/42186512/4561887). And, [my answer on how to do it high-speed in parallel](https://stackoverflow.com/a/76910116/4561887). – Gabriel Staples Aug 16 '23 at 02:27

4 Answers4

30

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
  • 106,657
  • 24
  • 210
  • 268
  • According to [the manual](http://manpages.ubuntu.com/manpages/trusty/man1/unzip.1.html) `unzip` doesn't support split archives (see the first paragraph in the section “Bugs”). – David Foerster Dec 23 '14 at 13:10
  • @DavidFoerster just tested it, and it works. – Mitch Dec 23 '14 at 14:03
  • Ok, then the manual appears to be wrong. Good catch. – David Foerster Dec 23 '14 at 14:38
  • @mitch in my case it doesnt work it sais "error while loading the zip file" but on windows the same directory on the same disk unzips with winrar, maybe you tried to unzip multiple but >separate< zip file simultanously? thats an other thing though. – papajo Oct 11 '17 at 00:39
4

To unzip multiple files using a loop -

for z in *.zip; do unzip "$z"; done
Rohith Madhavan
  • 8,229
  • 5
  • 24
  • 43
  • @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
0

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.
Gabriel Staples
  • 8,025
  • 7
  • 66
  • 105
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)