0

Ubuntu 16.04

I have a directory with zip files like this:

directory
|
|---zip1.zip
|---zip2.zip
|
...
|---zip_very_large_number.zip

Now, I have another directory /home/usrname/anotherdir. Is there a way to unzip all the files into the /home/usrname/anotherdir in the following way:

/home/usrname/anotherdir
|---zip1(directory)
|    |---_FILES_FROM_zip1.zip
|
|---zip2(directory)
|    |---_FILES_FROM_zip2.zip
|
|---zip3(directory)
|    |---_FILES_FROM_zip3.zip
|
...
|
|---zip_very_large_number(directory)
     |---_FILES_FROM_zip_very_large_number.zip

Is there a concise way to do this with unzip? I could write a shell-script but it doesn't look pretty well...

3

There is not a short way to do this with unzip, since it only accepts one zipfile for decompression at a time. Consider some sort of shell loop like:

for d in *.zip
do
  dir=/home/usrname/anotherdir/zip${d%%.zip}
  unzip -d "$dir" "$d"
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.