Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a single command to unzip every file in a directory, into a new unique directory with the same name as the file

Tags:

bash

unzip

I have a directory full of zip files. Each called something like 'files1.zip'. My instinct is to use a bash for loop to unzip each file.

Trouble is, many of the files will unzip their contents straight into the parent directory, rather then unfolding everything into their own unique directory. So, I get file soup.

I'd like to ensure that 'files1.zip' pours all of it's files into a dir called 'files1', and so on.

As an added complication, some of the filenames have spaces.

How can I do this?

Thanks.

like image 377
bob Avatar asked Jun 02 '11 20:06

bob


1 Answers

for f in *.zip; do
  dir=${f%.zip}

  unzip -d "./$dir" "./$f"
done
like image 68
Roland Illig Avatar answered Sep 21 '22 13:09

Roland Illig