Extracting several zip files, in a new folder with the same name, via Ubuntu terminal


Extracting several zip files, in a new folder with the same name, via Ubuntu terminal is now easy .There are some situations where we have to extract many zip files of same name. If we try to extract the file named x.tar, we may have same file name in different folder. At that time when you extract it, the same named multiple files will be extracted. So, in order to get rid of this problem, to extract several similar name file i have given this following command.

METHOD 1:

Use unzip’s –d option to set an alternate directory, which will archive contents.

unzip -d a a.zip

 

unzip -d b b.zip

Within a find expression,  derive the name for the directory from the name of the zip file using shell parameter expansion.

find -name '*.zip' -exec sh -c 'unzip -d "${1%.*}" "$1"' _ {} \;

Test above command by echo command.

find -name '*.zip' -exec sh -c 'echo unzip -d "${1%.*}" "$1"' _ {} \;

and try another command given below.

while read -rd $'\0' f; do 

unzip -d "${f%.*}" "$f"

done < <(find -name '*.zip' -print0)

 

METHOD 2:

Type the following command

unzip '*.zip' -d /home/user/folder/
8:32 am