16

I have a bunch of zip files I want to unzip in Linux into their own directory. For example:

a1.zip a2.zip b1.zip b2.zip

would be unzipped into:

a1 a2 b1 b2

respectively. Is there any easy way to do this?

Alexander
  • 161
  • 1
  • 1
  • 3

4 Answers4

14

Add quotes to handle spaces in filename.

for file in *.zip
do
  unzip -d "${file%.zip}" "$file"
done
Dave
  • 628
  • 7
  • 14
ghostdog74
  • 327,991
  • 56
  • 259
  • 343
12
for zipfile in *.zip; do
    exdir="${zipfile%.zip}"
    mkdir "$exdir"
    unzip -d "$exdir" "$zipfile"
done
Cascabel
  • 479,068
  • 72
  • 370
  • 318
1
for x in $(ls *.zip); do
 dir=${x%%.zip}
 mkdir $dir
 unzip -d $dir $x
done
Steve B.
  • 55,454
  • 12
  • 93
  • 132
  • You just barely beat me, but enough differences I posted anyway - you don't need to use ls (the globbing will expand just fine on its own), you don't need `%%` (it deletes the longest match, and there's only one possible match, picky, I know), and it's always good to quote your filenames! – Cascabel Mar 17 '10 at 16:21
1

Sorry for contributing to an old post, this works in cmd line for me and it was a life saver when I learnt about it

for file in $(ls *.zip); do unzip $file -d $(echo $file | cut -d . -f 1); done

Hey presto!

jhscheer
  • 342
  • 1
  • 8
  • 18
SJK
  • 91
  • 1
  • 10