Skip to main content
Removed line numbers
Source Link
dr_
  • 32.4k
  • 22
  • 102
  • 147

I needed a solution like Giles' from 2010, except I needed to preserve the folder structure, not unzip everything into the top level directory. Here's my take on his with three lines added/changed:

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

I needed a solution like Giles' from 2010, except I needed to preserve the folder structure, not unzip everything into the top level directory. Here's my take on his with three lines added/changed:

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

I needed a solution like Giles' from 2010, except I needed to preserve the folder structure, not unzip everything into the top level directory. Here's my take on his with three lines added/changed:

#!/bin/bash
shopt -s globstar nullglob
while set -- **/*.zip; [ $# -ge 1 ]
do
    for z
    do
        ( cd -- "$(dirname "$z")" &&
            z=${z##*/} &&
            cp -- "$z" "$z".bak &&
            mkdir -- "$z"dir &&
            unzip -- "$z" -d "$z"dir &&
            rm -- "$z"
        )
    done
done
Source Link

I needed a solution like Giles' from 2010, except I needed to preserve the folder structure, not unzip everything into the top level directory. Here's my take on his with three lines added/changed:

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