I have a list with the path of .zip files, gathered by the command below. I want to unzip them into that directory, where they exist.

find . -name "*.zip" -print > outfile.txt

outfile.txt is like:


I have run_all script to automatize it, but how can I define the output directory?

run_all outfile.txt 'unzip -u $1'

1 Answer 1


Use the -d flag.

unzip -d output_dir/ zipfiles.zip

To automate it:

for i in `cat outfile.txt`; do
    output_dir=$(dirname $i)
    unzip -d $output_dir $i

EDIT: As @dessert suggests, you may do this as a better alternative:

while IFS='' read -r i || [[ -n "$i" ]]; do unzip -d ${i%/*} $i; done <outfile.txt
  • This will break on a single whitespace in a path, you should rather use read. Additionally the bash shell can do dirname's work with parameter expansion: while IFS='' read -r i || [[ -n "$i" ]]; do unzip -d ${i%/*} $i; done <outfile.txt.
    – dessert
    Jan 11, 2018 at 10:18

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.