With this command

find . -name '*.zip' -exec unzip '{}' ';'

we find all zip files under . (directory), then unzip them into the current working directory, However, the structure is gone.


Current command result:

desired  result  

Asked here, but the code doesn't work out What should dirname and basename be in this command?


1 Answer 1


You can use find with the -execdir argument instead of -exec.

-execdir will run the command in the directory it has found the files in, instead of your current working directory


find . -name '*.zip' -execdir unzip {} \;

While this is not exactly what you've asked for, you could add a few steps to get to the desired result:

mkdir new
cp -a backUP/* new/
#run unzip operation
cd new
find . -name '*.zip' -execdir unzip {} \;
#remove all .zip files
find . -name '*.zip' -exec rm {} \;

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.