← Back to Archives

Removing Spaces from Filenames

hacks

Here's a great little script, written in bash, for removing spaces from filenames... it replaces them with an underscore. (I can't remember where I found this, but it's useful):

#!/bin/bash for oldName in "$@" ; do     newName=`echo ${oldName} | sed "s/ /_/g"`     if [ "${oldName}" != $newName ] ; then         mv "${oldName}" $newName     fi done

Note: Put it somewhere central (like /usr/local/bin/), make it executible (chmod +x) and add an alias in your .tcshrc or .csrhc or whatever.