Ogrim.no

Programing, Hacking, and the likes

Recursive Unzip in Bash

| Comments

There is a lot of data I need to extract from archives, nested deeply within a silly folder structure. Doing it manually is out of the question. I had to modify this script I found at the Unix Stack Exchange slightly, in order to make it run as I wanted. It will run until it doesn’t find more .zip archive files, as it deletes them after extraction.

I put this into a file:

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
shopt -s globstar nullglob
while set -- **/*.zip; [ $# -ge 1 ]
do
    for z
    do
        ( cd -- "$(dirname "$z")" &&
            z=${z##*/} &&
            unzip -- "$z" &&
            rm -- "$z"
        )
    done
done

then made it executable with chmod +x and stuck it on my path. Now I can easily unzip all the archive files recursively, from the folder where I call the script.

Comments