tags:

views:

161

answers:

3

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?

+1  A: 
for x in $(ls *.zip); do
 dir=${x%%.zip}
 mkdir $dir
 unzip -d $dir $x
done
Steve B.
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!
Jefromi
+1  A: 
for zipfile in *.zip; do
    exdir="${zipfile%.zip}"
    mkdir "$exdir"
    unzip -d "$exdir" "$zipfile"
done
Jefromi
+2  A: 
for file in *.zip
do
  unzip -d "${file%.zip}" $file
done
ghostdog74