I have a zip archive with lots of files and a plaintext file with list of files (~10000 items), that I need to extract from that archive using bash.

What is the best way to perform that operation? Obvious way is to run unzip for each line of file, but it looks to be very slow.

migrated from stackoverflow.com Feb 7 '13 at 11:00

This question came from our site for professional and enthusiast programmers.


Instead of running unzip on each file, you can run on the entire list of files by feeding the plaintext file as input:

unzip -j MyZipFile.zip <<<textfile
  • On macosc '-j' is junk paths is that not the same on your system ? Therefore that doesn't work for me. – sotapme Feb 7 '13 at 10:38
  • I don't have to access to the machine that I tested it on :) I am at work now where I use different Linux, not sure if there's a difference in zip across flavours. But you can just ignore -j and zip MyZipFile.zip <<<file should work. – P.P. Feb 7 '13 at 10:48

Unzip supports to specify which files to extract:

unzip archive.zip file1.txt file2.txt file3.txt ...

But this won't work for 10000 items. You can split your list of files into chunks of 100 and run unzip with them, this would be a faster implementation than extracting each file for itself.


You could use xargs with the -a option to read its arguments from a file. Probably also use a flag to limit the amount of arguments to an appropriate amount to ensure there aren't too many for the shell to handle if there is such a limitation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy