Convert a string to upper or lower case in bash

If you want change a string to lower, do this:

echo XpTo | tr “[:upper:]” “[:lower:]”

for all files in a directory you can do with the for command:

for i in * ; do cp $i ../wordpress_gallery/`echo $i | tr “[:upper:]” “[:lower:]”` ; done

To upper, you only need to change the parameters order:

echo XpTo | tr “[:lower:]” “[:upper:]”

One thought on “Convert a string to upper or lower case in bash”

Leave a Reply

Your email address will not be published. Required fields are marked *