The other day I needed to convert all folders, their subfolders, and all containing files from uppercase to lowercase on a UNIX machine. I’m not as saavy with UNIX as I’d like to be, but after a little trial and error came up with a script that did what I needed it to do. I couldnt find anything to do exactly what I needed online, so hopefully this will come in useful for somebody.
#!/bin/bash
if [ -n "$1" ]
then
if [ -d "$1" ]
then cd “$1″
else
echo Invalid Directory
exit
fi
fi
for x in `find . -type d`
do new=`echo $x | tr ‘[:upper:]‘ ‘[:lower:]‘`
mv $x $new
done
for x in `find . -type f`
do new=`echo $x | tr ‘[:upper:]‘ ‘[:lower:]‘`
mv $x $new
done
Just put this in a file and run it with the path to your directory as the input parameter.
Post a Comment