Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 26th September 2009, 11:45 PM
BravoMike's Avatar
BravoMike Offline
Registered User
 
Join Date: Feb 2009
Location: Glasgow, Scotland
Posts: 18
linuxfedorafirefox
Renaming Command

I have all my music on an external HD and the filename and path of each file is in the format of the following

Code:
Ex HD Root / Music / Artist / Album / Artist - Album - Track No - Track Name.mp3
OCD I know

Each Album folder has a file in it named

Code:
Artist Name - Album - Abum Cover.jpg
Needless to say, this file is the album cover.

In order to get it working with iTunes in my Windows XP partition I was planning to rename all image files to folder.jpg

If I was to run the following command in the Root / Music folder, would it produce the required results?

Code:
mv -rf *.jpg folder.jpg
__________________
Whiskey and sudo don't mix.
Reply With Quote
  #2  
Old 27th September 2009, 12:33 AM
parish Offline
Registered User
 
Join Date: Feb 2005
Posts: 594
linuxfedorafirefox
I don't think this would work, not to mention I'm unfamiliar with the -r option to mv.

The following is one way you can accomplish what you want using csh command syntax (bash syntax is likely slightly different):

cd /Music
find . -iname '*.jpg'

Look through the output of this find command and make sure you will only be renaming the files you intend to rename, then use the following commands to do the actual renaming

foreach i ( `find . -iname '*.jpg'` )
mv $i $i:h/folder.jpg
end


When you actually paste it in it will look something like this:

[202]% foreach i ( `find . -iname '*.jpg'` )
foreach? mv $i $i:h/folder.jpg
foreach? end
[203]%


Better yet, substitute cp for mv in the above foreach loop to preserve your original files.

Daniel
Reply With Quote
  #3  
Old 28th September 2009, 06:08 PM
BravoMike's Avatar
BravoMike Offline
Registered User
 
Join Date: Feb 2009
Location: Glasgow, Scotland
Posts: 18
linuxfedorafirefox
Thanks for the reply, Parish.

I realised that I stupidly assumed that mv would have a recursive tag much like cp, however after reading the man page I see this is not the case.

Taking your idea of using a for loop, I ended up with the following bash script

Code:
IFS=$'\t\n'
for i in $( find . -iname '*.jpg' ) 
do echo "Renaming " $i
cp $i ${i%/*}/folder.jpg
done
I have tested it out on some dummy folders and it works great.

Had to add in that first line because all of my files have spaces in the name, also I took the idea of using cp instead of mv, just incase it all goes FUBAR

Rather than using it as a script I just condensed it into one line, and here it is just in case anyone needs it.

Code:
IFS=$'\t\n'; for i in $( find . -iname '*.jpg' ); do echo "Renaming " $i; cp $i ${i%/*}/folder.jpg; done
__________________
Whiskey and sudo don't mix.
Reply With Quote
Reply

Tags
command, renaming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming a pen drive xaoxoa Hardware & Laptops 3 24th July 2009 03:09 PM
Renaming multiple directories by the command line Bezique Linux Chat 2 10th March 2008 06:29 AM
many files renaming pitat450 Using Fedora 3 9th February 2006 09:44 PM


Current GMT-time: 14:50 (Tuesday, 21-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat