Recursively extract files

February 11th, 2010 by Sameer | Filed under Hosting.

i want to recursively unzip into proper folder
so i have
/home/abdullah/quran1/files.zip

/home/abdullah/quran2/files.zip

/home/abdullah/quranfolder/files.zip

i simply want to unzip all of them at once, here is the shell script to do it in linux:

find -maxdepth 1 -mindepth 1 -type d | while read line; do unzip $line/*.zip -d $line ; done

This way is problematic if any of the folders have spaces in them

this way is better

for dir in */; do ( cd "$dir" && unzip *.zip ); done

Ref: http://unix.derkeiler.com/Newsgroups/comp.unix.misc/2005-03/0006.html

Here is an application of method 1 above, delete all files with 2008 in the name

find -name *2008* | while read line; do rm -f $line ; done

Other Interesting Posts

Leave a Reply