Friday, July 5, 2013

How to unzip a zip file into a folder with the zip file's name - Bash Script



cd into the directory containing the zip files
Run command

nano run.sh

Add below code to run.sh file

#!/bin/bash
for z in *.zip
do
d=`basename $z .zip`
mkdir $d && unzip $z -d $d
done


Make it executable

chmod +x run.sh

Run it

./run.sh

If you want to delete zip files after unzip, you only need to add
rm -rf $z after mkdir $d && unzip $z -d $d

No comments:

Post a Comment