i have a list of zip files, which each zip file in it has also some other zip files, and so on. I need to extract them all, with an ubuntu shell command, and get only the files with the extension *.pdf, into a new empty directory.

This is where i managed to come, i have tried unzip -l "*.zip"


From How do I recusively unzip nested ZIP files? comes this one-liner :

while [ "`find . -type f -name '*.zip' | wc -l`" -gt 0 ]; do find -type f -name "*.zip" -exec unzip -- '{}' \; -exec rm -- '{}' \;; done

This removes all zip files that were done in order to avoid infinite loops. If you want to conserve these files, take first a backup.

  • but how do i only keep files with the extension .pdf? – vipoxou Oct 12 '18 at 11:10
  • 1
    The above extracts all files. To extract only zip and pdf replace the command -exec unzip -- '{}' by the two commands -exec unzip -- '{}' "*.zip" \; -exec unzip -- '{}' "*.pdf.` – harrymc Oct 12 '18 at 13:52

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.