How do you recursively unzip archives in a directory and its subdirectories from the Unix command-line?

前端 未结 10 599
旧巷少年郎
旧巷少年郎 2020-12-04 07:15

The unzip command doesn\'t have an option for recursively unzipping archives.

If I have the following directory structure and archives:

/Moth         


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 07:34

    A solution that correctly handles all file names (including newlines) and extracts into a directory that is at the same location as the file, just with the extension removed:

    find . -iname '*.zip' -exec sh -c 'unzip -o -d "${0%.*}" "$0"' '{}' ';'
    

    Note that you can easily make it handle more file types (such as .jar) by adding them using -o, e.g.:

    find . '(' -iname '*.zip' -o -iname '*.jar' ')' -exec ...
    

提交回复
热议问题