Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

need to rename many files on linux server

Posted on 2014-02-18
7
Medium Priority
?
214 Views
Last Modified: 2014-02-27
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.
0
Comment
Question by:befidled
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 13

Expert Comment

by:Sandy
ID: 39867125
use cut command to get rid of it.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39867136
cd Images_directory
for file in $(ls *jpg); do  mv $file ${file%jpg}.jpg; done
0
 
LVL 13

Expert Comment

by:Sandy
ID: 39867148
excellent woolmilkporc :D
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 13

Expert Comment

by:Sandy
ID: 39867189
in case any file begins with jpg then use "#" instead of "%"

TY/SA
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 39867204
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
 
LVL 30

Expert Comment

by:serialband
ID: 39867721
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
 
LVL 1

Author Closing Comment

by:befidled
ID: 39893920
worked great! Thank you.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question