Created
February 10, 2015 09:47
-
-
Save Bonno/838e61fc27707ab9f22a to your computer and use it in GitHub Desktop.
Replace spaces in all files in given location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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