changing extension of multiple files
I have a directory with a ton of images in it and I'm trying to rename all of the files to have a specific extension (.thumb.jpg for thumbnails) here is what I have so far:
for file in *.jpg; do echo $file; mv $file $file.thumb.jpg; done EX: test.jpg -> test.thumb.jpg only problem is, the second argument to the mv includes the previous extension. I.E. test.jpg -> test.jpg.thumb.jpg Is there a wildcard that would drop the extension? ($file includes extension and I don't want that). I hope this isn't too confusing. I'm not entirely sure what I"m asking myself but I'm trying to make it as clear as possible. |
Just trying to get things clear....
You have files with the .jpg extension. What do you want them to look like? |
*.thumb.jpg
|
Is this what you want:
for file in *.jpg; do echo $file; echo ${file%%jpg} ; done blaat.jpg blaat. |
yes, thats exactly what i needed....thanks a ton.
you just save me hours of renaming and a lot of carpel tunnel pain! |
Rats, beat me to it! :) And here are a couple of other ways to do it.....
for i in *.jpg; do j=`echo $i | awk -F. '{print$1".thumb."$2}'`; mv "$i" "$j"; done or if using sed...... for i in *.jpg; do j=`echo $i | sed -e "s/".jpg"$/".thumb.jpg"/g"`; mv "$i" "$j"; done |
All times are GMT -5. The time now is 09:27 AM. |