Saturday, April 24, 2010

Converting spaces in filenames

Execute this simple one liner to convert spaces to underscores (You can replace this with any character you wish

find . -name "* *" | while read file; do target=`echo "$file"|tr -s ' ' '_'`; mv "$file" "$target"; done

2 comments:

  1. In ubuntu i simply use:

    rename 's/ /_/g' *

    But i don't know if all linux flavours support this.

    ReplyDelete
  2. Yeah rename is not a command in the OSX world...unfortunately. However, what I did was to wrap this command in a nice script called rename where I pass in the search/replace part...

    ReplyDelete