Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mrgreen4242

macrumors 601
Original poster
Feb 10, 2004
4,377
9
Hey all -

I'm trying to rename a bunch of files (namely, the file extension), but can't seem to make it work.

The DOS equivalent would be "ren *.m4a *.m4b". In Linux, I've done it with the mv command, which is what I THOUGHT I should be able to do in OS X's terminal, but alas, nothing.

Any help?
 
I know of no terminal command to rename files from x.m4a to x.m4b, y.m4a to y.m4b, etc., all at once, but you can build a simple shell script to do it, and there are a few tiny AppleScripts applications already floating around out there to do this. Perhaps somebody will post one here.

It would be fun to set up a Folder Action to do this, so you could drop an m4a file into a folder and have it be renamed automatically.
 
Code:
 # [A-Z]* matches upper case names
 for i in [A-Z]*
 do
        j=`echo $i | tr '[A-Z]' '[a-z]'`
        mv $i $j
 done

Maybe this script will work?

Haven't tried it myself.
 
I almost found a wacky Terminal command to do it:
Code:
find . -name '*.m4a' -exec mv {} `basename {} .m4a`.m4b \;
but it doesn't work for some reason. It leaves your file with a name like myfile.m4a.m4b. :(
 
Try this page for an explanation. It's quite old (1996) but I think it still applies. Bottom line is that the guy says you can do it from the c shell (tcsh on OS X) with:
Code:
	% foreach file (*.txt)
	> mv $file 'basename $file .txt'.sgl
	> end
(That is his code for his example.)

EDIT: Oh, if you're not stuck on using Terminal, you could just use a utility like R-Name to do it.
 
If you create a file named newsuffix containing these lines:
Code:
#! /bin/sh
for file in `ls *.$1 2>/dev/null` ; do
    base=`basename $file .$1`
    mv -n $base.$1 $base.$2
    done
then you can rename m4a files to m4b files by typing
Code:
sh newsuffix m4a m4b
If you give the command execute permission:
Code:
chmod +x newsuffix
and store it in a directory that is in your execution path, then you can type a simpler form:
Code:
newsuffix m4a m4b
 
HiRez said:
Try this page for an explanation. It's quite old (1996) but I think it still applies. Bottom line is that the guy says you can do it from the c shell (tcsh on OS X) with:
Code:
	% foreach file (*.txt)
	> mv $file 'basename $file .txt'.sgl
	> end
(That is his code for his example.)

EDIT: Oh, if you're not stuck on using Terminal, you could just use a utility like R-Name to do it.

Ah R-Name was perfect! Clearly I am not the only person who has had this issue, tho!

Thanks everyone!
 
Also, this sort of thing is relatively easy to do with Automator (in Tiger). First option in Automator needs to be "Get Selected Finder Items" then the 2nd (and final one) needs to be "Rename Finder Items." Under the 2nd part of Rename finder Items select "Replace Text" from the drop down menu and then type in your extension as the first text and your 2nd extension in the replace: box. Then all you have to do is select your mp3s in this case and run the script. You can save the script as a finder plugin by choosing "Save as a Plugin..." from the File Menu or hitting Option - OA - S. Enjoy. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.