Linux/Unix shell command   RENAME

willsherwood
willsherwood used Ask the Experts™
on
i need to rename all *.JPG to *.jpg  in a particular single directory (no recursion)

how can i accomplish this once i   CD to that directory?

something like   rename *.JPG *.jpg
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Try this:
for file in $(ls *.JPG)
do
   mv $file ${file%.*}.jpg
done

Open in new window

In one line you can write it as
 
for file in $(ls *.JPG); do mv -f $file ${file%.*}.jpg; done

Open in new window


It is different from Windows.  You will NOT find any one single command in Linux that would do your job

Author

Commented:
that was easy!  thanks!
Top Expert 2007

Commented:
Even easier if you use the 'rename' command.

Unfortunately this comes in two flavours on Linux systems, so you either need to do:

rename .jpg ,JPG *.JPG

Open in new window



or

rename 's/JPG/jpg/' *.JPG

Open in new window

Top Expert 2007

Commented:
Small typo.

rename .jpg ,JPG *.JPG

Open in new window


should be

rename .jpg .JPG *.JPG

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial