Search code examples
bashunziprm

Recursively unzip files and then delete original file, leaving unzipped files in place from shell


I've so far figured out how to use find to recursively unzip all the files:

find . -depth -name `*.zip` -exec /usr/bin/unzip -n {} \; 

But, I can't figure out how to remove the zip files one at a time after the extraction. Adding rm *.zip in an -a -exec ends up deleting most of the zip files in each directory before they are extracted. Piping through a script containing the rm command (with -i enabled for testing) causes find to not find any *.zips (or at least that's what it complains). There is, of course, whitespace in many of the filenames but at this point syntaxing in a sed command to add _'s is a bit beyond me. Thank for your help!


Solution

  • have you tried:

    find . -depth -name '*.zip' -exec /usr/bin/unzip -n {} \; -exec rm {} \;
    

    or

    find . -depth -name '*.zip' -exec /usr/bin/unzip -n {} \; -delete
    

    or running a second find after the unzip one

    find . -depth -name '*.zip' -exec rm {} \;