How do I recursively unzip nested ZIP files?

后端 未结 4 498
无人共我
无人共我 2021-01-06 00:45

Given there is a secret file deep inside a nested ZIP file, i.e. a zip file inside a zip file inside a zip file, etc...

The zip files are named 1.zip, <

相关标签:
4条回答
  • 2021-01-06 01:06

    Here's my 2 cents.

    #!/bin/bash
    
    function extract(){
      unzip $1 -d ${1/.zip/} && eval $2 && cd ${1/.zip/}
      for zip in `find . -maxdepth 1 -iname *.zip`; do
        extract $zip 'rm $1'
      done
    }
    
    extract '1.zip'
    
    0 讨论(0)
  • 2021-01-06 01:12

    Thanks Cyrus! The master wizard Shawn J. Goff had the perfect script for this:

    while [ "`find . -type f -name '*.zip' | wc -l`" -gt 0 ]; do find -type f -name "*.zip" -exec unzip -- '{}' \; -exec rm -- '{}' \;; done
    
    0 讨论(0)
  • 2021-01-06 01:13

    Probably not the cleanest way, but that should do the trick:

    #!/bin/sh
    IDX=1 # ID of your first zip file
    while [ 42 ]
    do
        unzip $IDX.zip # Extract
        if [[ $? != 0 ]]
        then
            break # Quit if unzip failed (no more files)
        fi
        if [ $IDX -ne 1 ]
        then
            rm $IDX.zip # Remove zip to leave your directory clean
        fi
        (( IDX ++ )) # Next file
    done
    
    0 讨论(0)
  • 2021-01-06 01:17

    Checkout this java based utility nzip for nested zips.

    Extracting and compressing nested zips can be done easily using following commands:

    java -jar nzip.jar -c list -s readme.zip 
    
    java -jar nzip.jar -c extract -s "C:\project\readme.zip" -t readme 
    
    java -jar nzip.jar -c compress -s readme -t "C:\project\readme.zip" 
    
    PS. I am the author and will be happy to fix any bugs quickly.
    
    0 讨论(0)
提交回复
热议问题