need to rename many files on linux server

I have a website where the previous developer uploaded hundreds of jpg images but included jpg in the filename but not as a suffix. So for instance the images are named like this:

Images directory:
imageonejpg
imagetwojpg
imagethreejpg
etc.

From the command line can I rename all the images in a directory so that they will look like the following?

Images directory:
imageone.jpg
imagetwo.jpg
imagethree.jpg
etc.
LVL 1
befidledAsked:
Who is Participating?
 
woolmilkporcConnect With a Mentor Commented:
If there are already some files with correct suffixes ".jpg" you can skip them with this:

cd Images_directory
for file in $(ls *jpg | grep -v "\.jpg$"); do mv $file ${file%jpg}.jpg; done
0
 
SandyCommented:
use cut command to get rid of it.
0
 
woolmilkporcCommented:
cd Images_directory
for file in $(ls *jpg); do  mv $file ${file%jpg}.jpg; done
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
SandyCommented:
excellent woolmilkporc :D
0
 
SandyCommented:
in case any file begins with jpg then use "#" instead of "%"

TY/SA
0
 
serialbandCommented:
Depending on your distribution, there may be a rename command now in /usr/bin/rename that uses perl regular expressions that allows you to rename multiple files.
0
 
befidledAuthor Commented:
worked great! Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.