batch renaming files in the Terminal

Posted:
in Genius Bar edited January 2014
OK, I thought this was simple but it seems to have stumped the Unix gurus out there...





All I want to do is rename all the files in a folder so that they have '.html' on the end of the filename? currently they have no file extension.

how hard can this be?

Comments

  • Reply 1 of 4
    dmgeistdmgeist Posts: 153member
    First: make sure you don't have Always show file extensions in the finder prefrences.

    Second: Select all of the files in the folder and show file info(cmd-i)

    you should be able to change file properties doing that.

    Third: Sometimes even if a file is an HTML, MP3, etc... it might not

    have the .ext on it. You can also change what application it opens with

    by using cmd-i.
  • Reply 2 of 4
    Here ya go. Use this shell script. This script will rename all files in the current directory. Don't forget to do a chmod +x.



    #!/bin/sh



    FS=`ls`



    for FILE in $FS

    do

    mv $FILE $FILE.html

    done
  • Reply 3 of 4
    mrbilldatamrbilldata Posts: 489member
    This script will rename all files in the given directory name and its sub-directories.



    #!/bin/csh

    # directory_name can be . or and directory

    find directory_name ! -type d -exec mv {} {}.html \\;



    #!/bin/csh

    # directory_name is entered as a parameter when the script is run

    find \\!* ! -type d -exec mv {} {}.html \\;



    Kenny must live... to die



    [ 06-25-2002: Message edited by: MrBillData ]</p>
  • Reply 4 of 4
    mrbilldatamrbilldata Posts: 489member
    The second method will also allow for more than one directory name to be given as a parameter.
Sign In or Register to comment.