Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

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

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

3 Answers 3

up vote 2 down vote accepted

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
share|improve this answer
    
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. –  KingsIndian 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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.