My directory tree looks like this:
../files/Italy.Pictures.Tom.Canon.2017-April/
../files/Italy.Videos.Marie.Sony.2017-April/
../files/Spain.Pictures.Food.John.iPhone.2018-September/
and so on..
My code:
#!/bin/bash
DIR="/home/user/files/"
find $DIR -depth -name "* *" -execdir rename 's/ /./g' "{}" \; # replace space with dot
find $DIR -depth -iname "*.iphone*" -execdir rename 's/.iphone//ig' "{}" \; # remove 'iPhone' from dir name
find $DIR -depth -iname "*.john*" -execdir rename 's/.john//ig' "{}" \;
find $DIR -depth -iname "*.tom*" -execdir rename 's/.tom//ig' "{}" \;
find $DIR -depth -iname "*-april*" -execdir rename 's/-april//ig' "{}" \;
find $DIR -depth -iname "*-september*" -execdir rename 's/-september//ig' "{}" \;
and more commands like this for all names, month,..
Yes, this works!
But: Is this the best way to remove/replace characters in directory names? Any suggestions to make my script more efficient? Maybe, to put all words in a list, which should be removed?
Thanks for your thoughts!