Renaming Files

Discussion in 'Mac Apps and Mac App Store' started by firewire2001, Feb 22, 2005.

  1. firewire2001 macrumors 6502a

    Joined:
    Apr 2, 2002
    Location:
    Hong Kong
    #1
    Hey,

    I have this directory of files that has files like this: hh-head.gif, hh-foot.gif, hh-next.gif, hh-previous.gif. (And so on for about 1000 files)

    So my question is, how could I rename these files so that they dont have the "hh-" part before them using the terminal? I'd rather not use Applescript for this job. I figure that I might need to make use of the MV command, but beyond that, I have no clue.

    Anyone have any ideas here?
     
  2. yellow Moderator emeritus

    yellow

    Joined:
    Oct 21, 2003
    Location:
    Portland, OR
  3. jywv8 macrumors 6502

    Joined:
    Jan 11, 2003
    Location:
    Chicago
    #3
    A little shell script would do the trick. Use a text editor to create a little text file named "rename.sh" (or whatever) and type the following into the file:

    for file in hh-*; do
    mv $file `echo $file | sed 's/hh-\(.*\)/\1/'` ;
    done;


    Save the script to the directory containing your "hh-" files, and then use Terminal to navigate to that directory. From the command line, type:

    sh rename.sh

    (or whatever you named your file).
     

Share This Page