0

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.

/backUp/pic1/1-1.zip
/backUp/pic1/1-2.zip
/backUp/pic2/2-1.zip
/backUp/pic2/2-2.zip
/backUp/pic3/3-1.zip
/backUp/pic3/3-2.zip
/backUp/pic3/3-3.zip

Current command result:
/new/1-1
/new/1-2
/new/2-1
/new/2-2
/new/3-1
/new/3-2
/new/3-3





desired  result  
/new/pic1/1-1 
/new/pic1/1-2 
/new/pic2/2-1
/new/pic2/2-2
/new/pic3/3-1
/new/pic3/3-2
/new/pic3/3-3

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

2

1 Answer 1

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

Example:

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 {} \;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .