Results 1 to 10 of 10
Hello, I'm a relatively new user to Linux using the Mint Isadora distro.
I was under the mistaken impression that somewhere in my audio adventures, I had inadvertently renamed all ...
- 10-12-2010 #1Just Joined!
- Join Date
- Sep 2008
- Posts
- 11
renaming files recursively
Hello, I'm a relatively new user to Linux using the Mint Isadora distro.
I was under the mistaken impression that somewhere in my audio adventures, I had inadvertently renamed all my mp3 files with an extra mp3 extension, e.g. StairwaytoHeaven.mp3.mp3. So I deleted the mp3 extensions from a lot of my music before I figured it out.
It didn't bother Rhythmbox any, but Banshee's not having it.
I've researched a bit looking for a way to use the find command or a Bash script to put the mp3 extensions back. I think my struggle is finding the syntax to say, "change all the files that have no extension (*.)? to the same name, but append mp3 to the end." I'm guessing that *. is actually denoting directories, not the files whose extensions I wiped out.
One small glimmer of hope: for some reason, the OS still remembers that some of the files are MP3., regardless of their extension, so perhaps there's a way to capitalize on that.
Thanks in advance for any help!
Jim
- 10-12-2010 #2
Linux Phrasebook by Scott Granneman is for you, my friend!
- 10-25-2010 #3Just Joined!
- Join Date
- Sep 2008
- Posts
- 11
OK, it's a pretty good book, and not too expensive. Thanks for the referral.
But it doesn't quite get me there.
I've come down to a question of either using find or a for/do loop.
The good thing about find is that it's recursive, and I can limit the operation of appending .mp3 to files, and not end up renaming all my directories as well.
The good thing about the for do loop is that I can use mv to easily make the change to the filenames. I tried a hybrid:
find . -type f | for i in *; do mv "$i" "$i".mp3 ; done
thinking that I would get the benefits of both, but it ended up being neither recursive, nor preventing the renaming of the directory.
I've read up on making mv recursive, and that looks like something I don't want to mess with.
So I looked back a thet find command. I tried:
find . -type f -exec rename * *.mp3 {} \;
but get this in reply:
Bareword "mp3" not allowed while "strict subs" in use at (eval 1) line 1.
I searched the error, and got a lot of perl and sql hits that I don't think were relevant.
Thanks in advance!
- 10-25-2010 #4
are you looking for command like "rename"?
How to Bulk Rename Files in Linux (Terminal or GUI) | Webmaster Tips- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 10-25-2010 #5Linux Guru
- Join Date
- Oct 2007
- Location
- Tucson AZ
- Posts
- 1,939
I remember looking for a way to add extensions to files several months ago using the rename command. Never found anything that worked which of course, does not mean it doesn't exist. The mv command below will add .mp3 extensions to files if you use it while in the directory. Of course, it will add mp3 to all files in that directory whether they are music files or not. Your post seems to indicate you have a large number of directories and files so this probably won't help too much?
for old in *;do mv $old `basename $old`.mp3;done
- 10-26-2010 #6Just Joined!
- Join Date
- Sep 2008
- Posts
- 11
Yes, Yancek, the problem is that without the "find" command, it's not limited to files (as opposed to both files and directories,) and it's not recursive in to the subdirectories.
But I'm getting warmer.
I wrote a script:
#!/bin/bash
# recursively rename all files with a .mp3 extension without renaming directories.
for old in `find -type f`
do
mv $old `basename $old`.mp3
done
The idea is putting the find command in the for loop, rather than the other way around. It didn't work at first, because the spaces in the filenames confused things, but I ran detox [detox dot sourceforge dot net] on it, and after that, the script worked, sort of.
The only problem is that in addition to adding .mp3 to the filenames (worked like a charm, that part
,) the script pulls all the files out of the subdirectories, and puts them in the working (top) directory :/
So now, instead of
/Led_Zeppelin/IV/Stairway_to_Heaven
I have
/Led_Zeppelin/IV/
Stairway_to_Heaven.mp3
Thank God I ran it on a test directory first.
Any ideas for getting it to leave the files in the subdirectories? Again, thanks in advance.
- 10-29-2010 #7Just Joined!
- Join Date
- Sep 2008
- Posts
- 11
getting warmer...?
I tried the following:
find . -type f -exec mv $old `basename $old`.mp3 {} \;
but it says that basename is missing an operand
and then mv says it can't stat `.mp3 no such file or directory
So I think it's my syntax. I think basename doesn't know that $old is its operand
I'm guessing I need quotes or brackets or something to organize which part goes with what, like parentheses in a long algebraic equation to show the order of operations.
Any ideas?
Thanks again,
Jim
- 10-29-2010 #8Linux Guru
- Join Date
- Oct 2007
- Location
- Tucson AZ
- Posts
- 1,939
I don't know if this will do anything, I haven't tested it but have you tried something like:
Just guessing with the above so if you try it, do it in a test directory with some empty files.Code:find . -type f -exec; for old in *;do mv $old `basename $old`.mp3;done
- 10-30-2010 #9Just Joined!
- Join Date
- Sep 2008
- Posts
- 11
Thanks, Yancek, looks like I might be missing some semicolons. I"ll give it a go!
- 11-29-2010 #10Just Joined!
- Join Date
- Sep 2008
- Posts
- 11
solved: renaming recursively
I found a combo of programs to do the job.
Detox renamed the filenames so they didn't cause shell errors,
and Metamorphonse 2 renamed them to fix the missing mp3 extensions.


Reply With Quote