Shell Scripting: Convert Uppercase to Lowercase

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 [donotprint]
Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time 2m
[/donotprint]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 #

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 23 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
23 comments… add one
  • Lucas Vieites Feb 18, 2009 @ 11:28

    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?

  • Raja Baz Jul 28, 2009 @ 10:47

    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]
  • Raja Baz Jul 28, 2009 @ 10:48

    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’

  • sanjay Katiyar Aug 7, 2009 @ 7:40

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

  • vinutha Sep 5, 2009 @ 4:46

    show the correct program fully

  • Asun Friere Sep 7, 2009 @ 4:53

    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])

  • reneuend Sep 16, 2009 @ 14:56

    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;

  • Joseph Nov 1, 2010 @ 15:39

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

    • Anil Nov 26, 2010 @ 7:39

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

  • irshad Dec 7, 2010 @ 17:46

    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

  • migyudtfr Mar 6, 2011 @ 20:11
    #! /bin/bash
    typeset -l string
    string="HELLO WORLD"
    echo $string
    • chandra Sep 7, 2011 @ 14:17

      Nice example it helped my issue

  • Riot May 7, 2011 @ 18:52

    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^^*}

  • mdinaz Aug 11, 2011 @ 15:54

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

  • bdog Jul 2, 2012 @ 16:53

    Is this a backslash, or a single quote?

  • Ben Jul 29, 2012 @ 12:39

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

    Works also.

  • Perl! Aug 29, 2012 @ 15:32

    perl -pe ‘$_=uc’

  • Rahul Jan 11, 2013 @ 13:09

    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

  • ponnuvel Jun 24, 2014 @ 8:09

    no use…

  • panlex_2010 Sep 12, 2015 @ 16:52

    Another way (use “ucase” or “lcase”):

    echo $var | dd conv=lcase 2>/dev/null
  • bill Feb 24, 2016 @ 9:25

    try this:

    for it in d f; do find -depth -type $it |sort -r |while read aa; do mv "$aa" "${aa,,}"; done ; done

  • praveen Apr 8, 2016 @ 13:55

    for UserName in `cat users` ;
    PassWord=$( echo $( tr ‘[:lower:]’ ‘[:upper:]’ <<< ${UserName:0:1} )${UserName:1} ) ;

    can i understand cearly what does this code do to
    text in the users file

  • Ronnie Oct 30, 2016 @ 10:02

    Every file in the directory starting with a capital P to lower cases

    for i in `ls P*`; do mv $i $(echo $i | tr [[:upper:]] [[:lower:]]); done

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum