Results 1 to 2 of 2
I have a question about renaming files. I found something posted on the forums that was close but not exact. The post was named 'file extension renaming (bash to csh)?'
...
- 04-25-2011 #1Just Joined!
- Join Date
- Jan 2010
- Location
- Houston
- Posts
- 8
File Rename
I have a question about renaming files. I found something posted on the forums that was close but not exact. The post was named 'file extension renaming (bash to csh)?'
Instead of wanting to rename the extension, I would like to rename the file name itself.
My situation is that I have a DSLR. When I upload pictures to my computer I get Image_0256.jpg, Image_0257.jpg, Image_0258.jpg etc. I have had up to 100 pictures when I upload them to my computer. I will then go back through the pictures and delete the junk pictures leaving only the good ones. So my final directory will have Image_0256.jpg, Image_0258.jpg, Image_0300.jpg, Image_0326.jpg etc. There is no numeric succession in the file naming.
I would like to script renaming the files in my picture directory from the current naming to (for example) Biking-001.jpg, Biking-002.jpg etc.
Is there a way to use an array feature of some sort that will allow me to rename all the files in the directory and automate the numbering of the files? I don't care which file becomes Biking-001 and which one becomes Biking-002. Ideally I would like the picture taken earlier in the day to be Biking-001.jpg. But at the end of the day I don't care as much as I care about the renaming function.
Thanks for your input and help. Let me know if I need to clarify what I'm wanting done.
- 04-25-2011 #2
Try this:
replacing searchstring and replacestring with the strings you want to find and replace. In your case, 'Image_' and 'Biking-' should work, leaving the number portion the same. If you want to change those to 001, etc, then you will need to modify the script to do that.Code:for i in * ; do j=`echo $i | sed 's#searchstring#replacestring#g' - ` ; mv "$i" "$j" ; done


Reply With Quote