Printable Version of Topic

Click here to view this topic in its original format

Linuxhelp _ Technical Support _ renaming files

Posted by: swbre Dec 8 2008, 07:42 PM

I had a bunch of files with filenames like DSCNnnnn.JPG where nnnn was a number between 3211 to 3271. I tried to change the name so the (caps) JPG would be lowercase jpg. I used
mv DSCN*.JPG DSCN*.jpg
and got an error message,
mv: target `DSCN*.jpg' is not a directory. I can do
mv DSCN3211.JPG DSCN3211.jpg
and that works ok. But I can't get the whole batch done with just one command. What am I doing wrong? How do I work around?
Thanks in advance.

Posted by: michaelk Dec 8 2008, 10:15 PM

Assuming you do not have lots of files (meaning many hundreds) here is a quick bash script.

for file in *.JPG; do
mv "${file}" "${file%JPG}jpg"
done

Posted by: swbre Dec 9 2008, 06:03 PM

QUOTE (michaelk @ Dec 8 2008, 10:15 PM) *
Assuming you do not have lots of files (meaning many hundreds) here is a quick bash script.


That works well. Thanks. How did you figure this out?

Posted by: michaelk Dec 9 2008, 06:50 PM

Reading, doing, trial and error, many years of experience, ..... and of course googling smile.gif
http://linux.die.net/abs-guide/
http://www.faqs.org/docs/abs/HTML/string-manipulation.html

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)