Today I had to re-write these scripts, that I used a lot when I took more photos than I do now. I´m pretty sure that I had versions of these scripts somewhere in my backup hard disk, but I can´t get it to work for some reason. BTW, that makes me pretty afraid, there are some important data on that disk, but I will face that problem some other day — plenty to do today already.
Without further ado:
Script for mass renaming files:
for i in *.jpg;
do mv $i `basename $i jpg`JPG;
done
Script for mass resizing pictures:
for i in *.JPG;
do convert $i -resize 600x600 `basename $i JPG`jpg;
done
¨basename¨ is a neat little program that I didn´t know about. It strips leading directories and trailing extensions from filenames (and if you give it the correct parameter, it will leave the period in the end of the file name). ¨convert¨ is a program in the Imagemagick package.
I usually use bash itself for renaming files:
for i in *.jpg; do mv $i ${i%jpg}JPG; done
${i%string} will take ‘string’ out of the end of $i. ${i#string} will take ‘string’ out of the beginning. A good mnemonic is that ‘#’ is before (to the left of) ‘%’ in the keyboard (so ‘#’ is in the beginning, ‘%’ in the end).
Nice, better than mine! I’ll update my scripts.
As for the mnemonic, recently I have been made to use (from time to time) a Spanish keyboard. The symbols are all in the wrong place! :-(