Converting all files in a directory to lowercase.

Converting all files in a directory to lowercase.

#!/bin/sh
# lowerit
# convert all file names in the current directory to lower case
# only operates on plain files–does not change the name of directories
# will ask for verification before overwriting an existing file
for x in `ls`
do
if [ ! -f $x ]; then
continue
fi
lc=`echo $x | tr ‘[A-Z]’ ‘[a-z]’`
if [ $lc != $x ]; then
mv -i $x $lc
fi
done

Wow. That’s a long script. I wouldn’t write a script to do that; instead, I would use this command:

for i in * ; do [ -f $i ] && mv -i $i `echo $i | tr ‘[A-Z]’ ‘[a-z]’`;
done;

on the command line.

Comments

comments

Powered by Facebook Comments

Leave a Reply

Content Protected Using Blog Protector By: PcDrome. & GeekyCube.