Need to remove text from file names using Terminal - possible?

Discussion in 'macOS' started by Cattywampus_, Nov 21, 2008.

  1. Cattywampus_ macrumors 6502a

    Apr 19, 2006
    Hi There

    I need a way to quickly remove text from a load of file names. I have ripped my DVD TV show series to my Apple TV and transfered them, but I want to make all the file names simpler that what they are currently. Changing them all through FTP would take ages - so I am hoping there is some kind of recursive command I can use to eliminate a set bit of text from a group of folders.

    Folder structures :

    External HDD Root
    |___TV Shows
    |___TV Show 1
    | |___Season1
    | | |_______ TV Show Name - 1x01 - Episode Name.avi
    | | |_______ TV Show Name - 1x02 - Episode Name.avi
    | |___Season2
    | |_______TV Show Name - 2x01 - Episode Name.avi
    | |_______TV Show Name - 2x01 - Episode Name.avi

    So the bit I want to remove is "TV Show Name - ". Just want to delete it from all the filenames.

    Anyone help? :)

  2. ergdegdeg Moderator emeritus


    Oct 13, 2007
    I think you'd be better off with a really quick Automator workflow. If you need help / tips just ask :)
  3. belvdr macrumors 603

    Aug 15, 2005
    In Linux this works, but not sure in OS X. Can you try this in Terminal first? If it works, then I'll post the rest of the script.

    find /path/to/shows -type f -name *.avi
    It should return a listing of all avi files. If not, I'll find a workaround.
  4. Cattywampus_ thread starter macrumors 6502a

    Apr 19, 2006
    Sorry I forgot to say.

    There is an External USB HDD connected to the ATV. I can only access it through FTP or SSH. I tried MacFusion to mount the drive in Finder, but it only mounts the internal HDD of the ATV. There is a Symbolic link but it won't actually navigate to the ext. drive.

    So yeah - it really needs to be a shell script :)

  5. belvdr macrumors 603

    Aug 15, 2005
    Here's what I've come up with:
    # Renames files from "TV Show Name - 2x01 - Episode Name.avi" to "2x01 - Episode Name.avi"
    for FILENAME in `find ${SHOWS_DIR} -type f -name *.avi`; do
    	NEW_FILENAME="$(echo "$FILENAME" | cut -d- -f2-)"
    	echo mv "${FILENAME}" "${NEW_FILENAME}"
    You should place this into a file and run it. It will output the commands. If the commands look okay, then remove the "echo" part of that line.

    This assumes the "TV Show Name" does not have any hyphens in it.

Share This Page