LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 05-23-2010, 08:31 AM   #1
unihiekka
Member
 
Registered: Aug 2005
Distribution: SuSE Linux / Scientific Linux / [K|X]ubuntu
Posts: 273

Rep: Reputation: 32
Rename recursively


How could I rename (lots of) files (recursively from the pwd) from *.jpg to cover.jpg? I have many different cover art files for my mp3s, but I want to rename them all to cover.jpg (in each folder). Thanks!
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 05-23-2010, 08:53 AM   #2
dmafcoi
LQ Newbie
 
Registered: May 2010
Posts: 22

Rep: Reputation: 0
Quote:
Originally Posted by unihiekka View Post
How could I rename (lots of) files (recursively from the pwd) from *.jpg to cover.jpg? I have many different cover art files for my mp3s, but I want to rename them all to cover.jpg (in each folder). Thanks!
Hi unihiekka: This LQ post should help.
 
Old 05-23-2010, 08:57 AM   #3
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
Hi,

for THISFILE in `find /mp3/base/dir/ -type f -name "*.jpg"`; do echo ${THISFILE} ${THISFILE%/*}"/cover.jpg"; done

This looks for jpg files in /mp3/base/dir/ (substitute with your mp3 base directory) and renames them to cover.jpg

If there are more the one jpg files in the same directory all will be renamed to cover.jpg and you will end up with 1 jpg file!! I do assume that all jpg's are in seperate dirs (one jpg per album).

I also assume that you have a base directory for mp3's. Something like this (names may differ):
/multimedia/mp3
/multimedia/mp3/Bauhaus
/multimedia/mp3/Japan


If a test run succeeds, change echo to mv.

Hope this helps.
 
2 members found this post helpful.
Old 05-23-2010, 09:00 AM   #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
Hi,

Quote:
Originally Posted by dmafcoi View Post
Hi unihiekka: This LQ post should help.
Not in this case, although some of the techniques used are somewhat similar.

The thread you refer to changes JPG to jpg, which is easier then changing xxxx.jpg to cover.jpg.
 
Old 05-23-2010, 09:14 AM   #5
dmafcoi
LQ Newbie
 
Registered: May 2010
Posts: 22

Rep: Reputation: 0
Quote:
Originally Posted by druuna View Post
Hi,
Not in this case...
That's why I said 'should help' not 'should solve it for you'

Pleasant day,
Bob
 
Old 05-23-2010, 01:33 PM   #6
unihiekka
Member
 
Registered: Aug 2005
Distribution: SuSE Linux / Scientific Linux / [K|X]ubuntu
Posts: 273

Original Poster
Rep: Reputation: 32
Quote:
for THISFILE in `find /mp3/base/dir/ -type f -name "*.jpg"`; do echo ${THISFILE} ${THISFILE%/*}"/cover.jpg"; done
Thanks for that. Another question. Somehow there are some files that are hidden, so they are of the form ".*.jpg". How would I go about changing that line to accommodate for that difference (I know that at least I should change the "*.jpg" to ".*.jpg", but then I would like the files to become normal, not hidden. That alone won't do, because then it cannot stat the files...) Any help much appreciated.
 
Old 05-23-2010, 01:54 PM   #7
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
Hi,

Did you try my command? It should pick up on the dot files as well:
Code:
/tmp/Temp $ ls -lAR
.:
total 16
drwxr-x--- 2 druuna internet 4096 May 23 19:52 a
drwxr-x--- 2 druuna internet 4096 May 23 19:52 b
drwxr-x--- 2 druuna internet 4096 May 23 19:52 c
drwxr-x--- 2 druuna internet 4096 May 23 19:52 d

./a:
total 0
-rw-r----- 1 druuna internet 0 May 23 19:46 .aaa.jpg

./b:
total 0
-rw-r----- 1 druuna internet 0 May 23 19:47 .bbb.jpg

./c:
total 0
-rw-r----- 1 druuna internet 0 May 23 19:47 zzz.jpg

./d:
total 0
-rw-r----- 1 druuna internet 0 May 23 19:52 zzz.jpg
druuna /tmp/Temp $ 

/tmp/Temp $ for THISFILE in `find /tmp/Temp/ -type f -name "*.jpg"`; do echo ${THISFILE} ${THISFILE%/*}"/cover.jpg"; done
/tmp/Temp/c/zzz.jpg /tmp/Temp/c/cover.jpg
/tmp/Temp/b/.bbb.jpg /tmp/Temp/b/cover.jpg
/tmp/Temp/d/zzz.jpg /tmp/Temp/d/cover.jpg
/tmp/Temp/a/.aaa.jpg /tmp/Temp/a/cover.jpg
druuna /tmp/Temp $
Bold lines are the dot files.

Hope this helps.
 
1 members found this post helpful.
Old 05-23-2010, 08:59 PM   #8
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Quote:
Originally Posted by unihiekka View Post
Thanks for that. Another question. Somehow there are some files that are hidden, so they are of the form ".*.jpg". How would I go about changing that line to accommodate for that difference (I know that at least I should change the "*.jpg" to ".*.jpg", but then I would like the files to become normal, not hidden. That alone won't do, because then it cannot stat the files...) Any help much appreciated.
Hi,

try
Code:
shopt -s dotglob
and then run the command in the same shell again. Should now also match files that start with a dot.
 
0 members found this post helpful.
Old 05-26-2010, 02:46 AM   #9
unihiekka
Member
 
Registered: Aug 2005
Distribution: SuSE Linux / Scientific Linux / [K|X]ubuntu
Posts: 273

Original Poster
Rep: Reputation: 32
Yes, druuna, you are right. I'm sorry. I did not see the hidden files in the list. There is however a catch. When I use echo, no problem. When I replace it with mv, it says cannot stat, probably because there are spaces in the folder names. Can that be an issue?
 
Old 05-26-2010, 02:54 AM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally Posted by unihiekka View Post
Yes, druuna, you are right. I'm sorry. I did not see the hidden files in the list. There is however a catch. When I use echo, no problem. When I replace it with mv, it says cannot stat, probably because there are spaces in the folder names. Can that be an issue?
Absolutely. You need to quote the names with spaces in them.
Code:
for THISFILE in `find /tmp/Temp/ -type f -name "*.jpg"`; do echo "${THISFILE}" "${THISFILE%/*}/cover.jpg"; done
... that *should* work (untested).
 
Old 05-26-2010, 02:55 AM   #11
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
Hi,

A possible solution for the spaces would be to change this:

echo ${THISFILE} ${THISFILE%/*}"/cover.jpg"

into:

echo "${THISFILE}" "${THISFILE%/*}/cover.jpg"

Hope this helps.

Beaten by The Tinkster
 
  


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to rename files recursively, only keeping last x digits plus extension furryspider Programming 2 11-29-2009 01:55 PM
Unrar and Rename to Parent Folder Recursively Vasto Linux - Newbie 9 10-16-2008 07:36 AM
Recursively - What? AndeAnderson Linux - Newbie 3 01-10-2007 10:57 AM
rm dir recursively allelopath Linux - General 6 01-06-2006 12:37 PM
How to recursively rename files using their directory name pattern ceg4048 Linux - General 2 09-28-2005 02:16 PM


All times are GMT -5. The time now is 03: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