My friend today asked me how to convert all spaces in filenames under a specified directory to underscores. Also, at the same time lowercase all of the filenames. Here is a quick script to do what is needed. Let us start with creating some test data in a temp directory:
touch Foo FooO "Foo Bar" "FOO BAaR"
\ls | while read -r FILENAME
mv -v "$FILENAME" `echo $FILENAME| tr ' ' '_'| tr '[A-Z]' '[a-z]'`
Note:Â I intentionally have slash in front of ls (\ls).Â \ls means that we want to make sure there is no ls …[Read more...]