Shell Scripting: Convert Uppercase to Lowercase

by on January 13, 2008 · 19 comments· LAST UPDATED February 24, 2014

in , ,

I've a small shell script and I would like to convert all incoming user input to lowercase using a shell script. How do I convert uppercase words or strings to a lowercase or vise versa on Unix-like / Linux bash shell?

Use the tr command to convert all incoming text / words / variable data from upper to lower case or vise versa (translate all uppercase characters to lowercase). Bash version 4.x+ user
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Estimated completion time2m
can use parameter expansion to modify the case of alphabetic characters in parameter.

Convert all text in a file from UPPER to lowercase

To translate or delete characters use tr command. The basic syntax is:

tr 'set1' 'set2' input


tr 'set1' 'set2' input > output

Type the following command at shell prompt:
$ tr '[:upper:]' '[:lower:]' < input.txt > output.txt
$ cat output.txt

Task: Convert Data Stored in a Shell Variable From UPPER to lowercase:

Type the following command:
$ echo $VAR_NAME | tr '[:upper:]' '[:lower:]'
$ echo $VAR_NAME | tr '[:lower:]' '[:upper:]'

Bash version 4.x+: Uppercase to lowercase or vice versa

The bash version 4.x+ got some interesting new features. Type the following commands to convert $y into uppercase:

y="this Is A test"
echo "${y^^}"

Sample outputs:


Type the following commands to convert $y into lowercase:

y="THIS IS a TeSt"
echo "${y,,}"

Sample outputs:

this is a test

Sample Shell Script

# get filename
echo -n "Enter File Name : "
read fileName
# make sure file exits for reading
if [ ! -f $fileName ]; then
  echo "Filename $fileName does not exists."
  exit 1
# convert uppercase to lowercase using tr command
tr '[A-Z]' '[a-z]' < $fileName
# Note Bash version 4 user should use builtins as discussed above 

Recommended readings:

# Additional correction by D.K.; Editing by VG - log #

Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 19 comments… read them below or add one }

1 Lucas Vieites February 18, 2009 at 11:28 am

This work fine when using latin characters, but not when using Unicode characters. For example a string with Cyrillic characters (“Английский”) doesn’t get converted. Any tips on how to do that?


2 Raja Baz July 28, 2009 at 10:47 am

Well, tr has no way of knowing what are uppercase and what are lowercase cyrillic characters. You need to provide it with this information.


The example above is equivalent to:

tr [ABCDEFGHIJKLMNOPQRSTUVWXYZ] [abcdefghijklmnopqrstuvwxyz]


3 Raja Baz July 28, 2009 at 10:48 am

Damn I didn’t notice this thing had html tags enabled and used angled brackets in my post. I meant:

tr [all uppercase cyrillic characters] [their lowercase equivalent]
instead of just ‘tr’


4 sanjay Katiyar August 7, 2009 at 7:40 am

Is there any options so that Other than first letter of a word get converted to lowercase


5 vinutha September 5, 2009 at 4:46 am

show the correct program fully


6 Asun Friere September 7, 2009 at 4:53 am

Is there any options so that Other than first letter of a word get converted to lowercase

You mean preserve the first and translate the rest? How about:
echo $(echo $VAR_NAME | cut -c1)$(echo $VAR_NAME | cut -c2- | tr [A-Z] [a-z])


7 reneuend September 16, 2009 at 2:56 pm

If you just want to change the case of the file extension, here is one way to do it:

for f in *.TXT; do mv $f `basename $f .TXT`.txt; done;


8 Joseph November 1, 2010 at 3:39 pm

Thanks for this opportunity, to ask this question, This is my question.


9 Anil November 26, 2010 at 7:39 am

cat | tr [[:upper:]] [[:lower:]]


10 irshad December 7, 2010 at 5:46 pm

hey guys your info has been really helpful. I m an Mca student and am vry good in C lang. Since it is embedd in ma brain, i feel it very hard to learn another script lang llike Unix but i want to perforn in Unix too. Could please help me by providn som basic tips so i can learn shell progming quickly.
Ur help vl b greatly appreciated


11 migyudtfr March 6, 2011 at 8:11 pm
#! /bin/bash
typeset -l string
string="HELLO WORLD"
echo $string


12 chandra September 7, 2011 at 2:17 pm

Nice example it helped my issue


13 Riot May 7, 2011 at 6:52 pm

In bash 4, the easiest and by far the most elegant way to do this for lowercase is:

echo ${string,,*}

and for uppercase:

echo ${string^^*}


14 mdinaz August 11, 2011 at 3:54 pm

This doesn’t work with the old Solaris version of tr, you need to use the GNU version in /usr/xpg4/bin on Solaris.


15 bdog July 2, 2012 at 4:53 pm

Is this a backslash, or a single quote?


16 Ben July 29, 2012 at 12:39 pm

$ echo ibm | awk ‘{ print toupper($1); }’

Works also.


17 Perl! August 29, 2012 at 3:32 pm

perl -pe ‘$_=uc’


18 Rahul January 11, 2013 at 1:09 pm

I need to write a shell script that copies a list of files from one directory to another. During copying the script should capitalize the first letter of the filename and lowercase all other letters.
I need the script as soon as possible.Please


19 ponnuvel June 24, 2014 at 8:09 am

no use…


Leave a Comment

Tagged as: , , , , , , , , , , , ,

Previous Faq:

Next Faq: