LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 01-29-2004, 12:53 PM   #1
shaggystyle
Member
 
Registered: Dec 2003
Location: Louisville, KY
Distribution: Gentoo (desktop), Mandrake 10.0 (server)
Posts: 39

Rep: Reputation: 15
changing extension of multiple files


I have a directory with a ton of images in it and I'm trying to rename all of the files to have a specific extension (.thumb.jpg for thumbnails) here is what I have so far:

for file in *.jpg; do echo $file; mv $file $file.thumb.jpg; done

EX: test.jpg -> test.thumb.jpg

only problem is, the second argument to the mv includes the previous extension. I.E. test.jpg -> test.jpg.thumb.jpg

Is there a wildcard that would drop the extension? ($file includes extension and I don't want that).

I hope this isn't too confusing. I'm not entirely sure what I"m asking myself but I'm trying to make it as clear as possible.
 
Old 01-29-2004, 12:58 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Just trying to get things clear....

You have files with the .jpg extension.
What do you want them to look like?
 
Old 01-29-2004, 12:59 PM   #3
shaggystyle
Member
 
Registered: Dec 2003
Location: Louisville, KY
Distribution: Gentoo (desktop), Mandrake 10.0 (server)
Posts: 39

Original Poster
Rep: Reputation: 15
*.thumb.jpg
 
Old 01-29-2004, 01:04 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Is this what you want:

for file in *.jpg; do echo $file; echo ${file%%jpg} ; done
blaat.jpg
blaat.
 
Old 01-29-2004, 01:09 PM   #5
shaggystyle
Member
 
Registered: Dec 2003
Location: Louisville, KY
Distribution: Gentoo (desktop), Mandrake 10.0 (server)
Posts: 39

Original Poster
Rep: Reputation: 15
yes, thats exactly what i needed....thanks a ton.

you just save me hours of renaming and a lot of carpel tunnel pain!
 
Old 01-29-2004, 01:35 PM   #6
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Rats, beat me to it! And here are a couple of other ways to do it.....

for i in *.jpg; do j=`echo $i | awk -F. '{print$1".thumb."$2}'`; mv "$i" "$j"; done

or if using sed......

for i in *.jpg; do j=`echo $i | sed -e "s/".jpg"$/".thumb.jpg"/g"`; mv "$i" "$j"; done
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing extension of multiple files harisund Programming 17 06-01-2006 11:59 AM
changing ownership and group of multiple files.. utanja Debian 3 02-21-2005 07:10 PM
symlink multiple files to new directory with new extension jmanjohn61 Linux - General 1 01-06-2005 01:55 PM
Extension files BC1 Linux - Software 5 12-20-2004 04:41 AM
How program to read files with extension .dat y .cfg files COMTRADE in fedora 1? ivonne Linux - Software 0 11-22-2004 12:42 PM


All times are GMT -5. The time now is 11:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration