简体   繁体   中英

How to unzip all zip folders in my subdirectories?

My folder structure

drwx------ 2 miki miki 4096 сеп 12  2018 Chapter03/
drwx------ 2 miki miki 4096 сеп 12  2018 Chapter05/
drwx------ 2 miki miki 4096 сеп 12  2018 Chapter07/
drwx------ 2 miki miki 4096 сеп 12  2018 Chapter09/
drwx------ 2 miki miki 4096 сеп 12  2018 Chapter10/
drwx------ 2 miki miki 4096 сеп 12  2018 Chapter13/
drwx------ 2 miki miki 4096 сеп 12  2018 Chapter14/
-rw-r--r-- 1 miki miki   96 сеп 12  2018 README.txt

Each chapter contains on ore more zip folders. I tried this way

unzip -d $(find ./ -type f -name '*.zip')

This does not work.

Archive:  ./Chapter14/kops-master.zip
4ffc8d76f1313a2f2a04a87d543a0701816c3df7
checkdir:  cannot create extraction directory: ./Chapter14/weave-kube-master.zip
           File exists

How should the proper command look like?

Try:

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

This runs unzip on each zip file found by your find command.

The above will work even if the zip files or directories have spaces or other difficult characters in their names.

Since zip files may contain/nest zip files, and we do not know the order of files reading in the find command. It is better to run find command twice, or 3 times. Corresponding to the zip nesting level.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM