A short script this week to replace spaces in filenames in a given folder:
# Looping over files, forging new filename, and then renaming it.
# Spaces will be replaced by underscores (_).
for oldname in *
do
newname=`echo $oldname | sed -e 's/ /_/g'`
mv "$oldname" "$newname"
done
# Spaces are now underscores
This one remove the spaces, only the sed expression is different:
for oldname in *
do
newname=`echo $oldname | sed -e 's/ //g'`
mv "$oldname" "$newname"
done
And this one lowercase all letters in addition to removing spaces:
for oldname in *
do
newname=`echo $oldname | sed -e 's/ //g' | tr '[:upper:]' '[:lower:]'`
mv "$oldname" "$newname"
done