Ubuntu – Extract multiple zip files from text list into their own folders with error log

archivecommand lineunzip

I wish to unzip ZIP files from a text list, each one into its own folder and output the errors into a log file.

The list looks like this:

0001.zip
0002.zip

I know i can use the following command but I just don't know how
to accomplish the above.

find -name '*.zip' -exec sh -c 'unzip -d "${1%.*}" "$1"' _ {} \;

Thank you.

Best Answer

Since you already have the extraction command sh -c 'unzip -d "${1%.*}" "$1"', you can use xargs to convert input files to arguments:

xargs -a list-of-files -L1 sh -c 'unzip -d "${1%.*}" "$1"' _

The {} is not needed since xargs by default appends the input to argument list. The -L1 makes it use one line of input as an argument.

Then just redirect the output to a file:

xargs -a list-of-files -L1 sh -c 'unzip -d "${1%.*}" "$1"' _ &> zip.log

Or just the errors:

xargs -a list-of-files -L1 sh -c 'unzip -d "${1%.*}" "$1"' _ 2> zip.log