Unzip All Files In A Directory
I have a directory of ZIP files (created on a Windows machine). I can manually unzip them using unzip filename
, but how can I unzip all the ZIP files in the current folder via the shell?
Using Ubuntu Linux Server.
This works in bash, according to this link:
unzip \*.zip
Just put in some quotes to escape the wildcard:
unzip "*.zip"
The following bash script extracts all zip files in the current directory into new dirs with the filename of the zip file, i.e.:
The following files:
myfile1.zip
myfile2.zip
Will be extracted to:
./myfile1/files...
./myfile2/files...
Shell script:
#!/bin/sh
for zip in *.zip
do
dirname=`echo $zip | sed 's/\.zip$//'`
if mkdir "$dirname"
then
if cd "$dirname"
then
unzip ../"$zip"
cd ..
# rm -f $zip # Uncomment to delete the original zip file
else
echo "Could not unpack $zip - cd failed"
fi
else
echo "Could not unpack $zip - mkdir failed"
fi
done