Stupid terminal question

Discussion in 'macOS' started by mrgreen4242, Oct 4, 2005.

  1. mrgreen4242 macrumors 601

    mrgreen4242

    Joined:
    Feb 10, 2004
    #1
    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?
     
  2. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #2
    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.
     
  3. dubbz macrumors 68020

    dubbz

    Joined:
    Sep 3, 2003
    Location:
    Alta, Norway
    #3
    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.
     
  4. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #4
    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. :(
     
  5. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #5
    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.
     
  6. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #6
    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
     
  7. mrgreen4242 thread starter macrumors 601

    mrgreen4242

    Joined:
    Feb 10, 2004
    #7
    Ah R-Name was perfect! Clearly I am not the only person who has had this issue, tho!

    Thanks everyone!
     
  8. Billicus macrumors 6502a

    Billicus

    Joined:
    Apr 3, 2002
    Location:
    Charles City, Iowa
    #8
    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. :)
     

Share This Page