#!/bin/bash
# script to decompress zips and copy used zips to dir
# the important directories
my_zip_dir="/home/USER/zip_dir"
my_pict_dir="/home/USER/pict_dir"
# the testing ----------------------------------------
# are there zip files
ls *.zip > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "zip files present, programm continues"
else
echo ERROR: no zip files found programm stops
exit 1
fi
# does pict dir exist
if [ -d "$my_pict_dir" ]; then
echo " ${my_pict_dir}..already there everything ok"
else
echo ERROR: picture dir doesnot exists programms stops
exit 1
fi
# does zip dir exists
if [ -d "$my_zip_dir" ]; then
echo " ${my_zip_dir}..already there"
else
mkdir "$my_zip_dir"
fi
# end of testing ---------------------------------------------
# the unzipping ---------------------------------------------
for i in *.zip;
do filename=$(basename "$i")
extension="${filename##*.}"
filename="${filename%.*}"
echo "$filename"
DIR=/home/USER/target_dir/"$filename"
if [ -d "$DIR" ]; then
echo " ${DIR}..already there"
else
mkdir "$DIR"
fi
if [ $? -eq 0 ]; then
unzip -nq "$i" -d "$DIR"
if [ $? -eq 0 ]; then
echo "unzip ok"
mv "$i" "$my_zip_dir"
else
echo "unzip failed"
fi
else
echo "could not make dir ${DIR} "
fi
done
# ----------------------------------------------------------------
echo programm ended
This script was made to unpack a bunch of zip files with old pictures. I have found the script somewhere on the internet and adapted it to my own needs.Â
What does the the script do:
- It test if zip files are present in the directory
- It tests whether your picture directory exists
- it tests if the directory where you want to put your zip files exists
- Makes a directory to store your files ins
- Â Unzips the files in the newly made directory
- move the zip file to a storage directory
How to use it:
- Make the script executable with chmod +x
- Edit the lines with the important directories
- In terminal. change to directory where the zip files are.
- Copy the script into this directory and run it.Â
For me it worked like a charm
Â
HP