1

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...

0

2 Answers 2

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 
3

Here is a one liner that works for any zips in the current directory

for z in *.zip; do unzip "$z" -d "${z%".zip"}"; done 

You can add it to your .bashrc

alias unzip_all='for z in *.zip; do unzip "$z" -d "${z%".zip"}"; done' 

Inspiration taken from:

Method #2: Unzipping Multiple Files from Linux Command Line Using Shell For Loop (Long Version) in https://www.cyberciti.biz/faq/linux-unix-shell-unzipping-many-zip-files/

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.