I'm trying to build an .sh-Script to help me clear a huge gallery folder. This is my first time with bash scripting and it's not working quite right.
Folder Structure is:
gallery/
gallery1/
dynamic/
thumbs/
oldfile.jpg_backup
oldfile.jpg
gallery2/
dynamic/
thumbs/
oldfile.jpg_backup
oldfile.jpg
.. and so on.
This is how it should work:
- Will be run in the main folder called 'gallery'
- Goes into every folder (gallery1, gallery2 etc.)
- Checks if the subfolder contains another subfolder called thumbs or dynamic, if yes it should delete them
- Check if there are files with a ".jpg_backup" extension in the folder
- If yes it deletes all regular .jpg files
- It renames als .jpg_backups to .jpgs
I tried it this way but im hanging on line "if [DIRECTORY]". This is purley made up since I have no idea how to do that part. Any help is greatly appreciated
for f in ~/gallery/*;
do
[ -d /thumbs ] && rm -r thumbs/ && echo Thumbs deleted...
[ -d /dynamic ] && rm -r dynamic/ && echo Dynamic deleted...
if [ DIRECTORY == "*.jpg_backup" ]
then
rm *.jpg
rename 's/.jpg_backup/.jpg/' *
fi
done;