Skip to content

Instantly share code, notes, and snippets.

@Bonno
Created February 10, 2015 09:47
Show Gist options
  • Save Bonno/838e61fc27707ab9f22a to your computer and use it in GitHub Desktop.
Save Bonno/838e61fc27707ab9f22a to your computer and use it in GitHub Desktop.
Replace spaces in all files in given location
if [ -n "$1" ]
then
if [ -d "$1" ]
then
cd "$1"
else
echo invalid directory
exit
fi
fi
for i in *
do
OLDNAME="$i"
NEWNAME=`echo "$i" | tr ' ' '_'`
if [ "$NEWNAME" != "$OLDNAME" ]
then
TMPNAME="$i"_TMP
echo ""
mv -v -- "$OLDNAME" "$TMPNAME"
mv -v -- "$TMPNAME" "$NEWNAME"
fi
if [ -d "$NEWNAME" ]
then
echo Recursing lowercase for directory "$NEWNAME"
$0 "$NEWNAME"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment