Reputation: 13
I'm trying to resize and rename several hundred subdirectories of images. The files that I need to be changed:
Example: images/**/[email protected]
I got the resizing bit down in one directory. I'm having some trouble finding a way to rename just the end of the file, not the extension, and executing it through the subdirectories.
Any help would be appreciated.
#!/bin/bash
for i in $( ls *A.jpg); do convert -resize 400x400 $i
Upvotes: 1
Views: 1312
Reputation: 207355
You can do this:
#!/bin/bash
find . -name "*A.jpg" | while read f
do
newname=${f/A.jpg/[email protected]}
echo convert "$f" -resize 400x400 "$newname"
done
Remove the word echo
if it looks correct, and run only on files you have backed up.
You can also do it in a one-liner, if you really want to:
find . -name "*A.jpg" -exec bash -c 'old="$0";new=${old/A.jpg/[email protected]};echo convert "$old" -resize 400x400 "$new"' {} \;
Upvotes: 2