Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Many times I have run a command with all the letters in uppercase (maybe because CapsLock was on), and I pressed Enter before realising this.

How can I run the last command with all the letters transformed to lowercase?

share|improve this question
Shame you're not using zsh. !!:l. – Kevin May 13 '14 at 20:13
up vote 19 down vote accepted

You can accomplish that by adding the following small function (I call it ?? to be very simple, but you can change this as you wish) in your .bashrc file:

?? () { "${@,,}"; }

Next, when you will run:

?? !!

the last command will be run with all the letters to lowercase.


  • !! : this is part of bash's history tools, specifically, it expands to the last command run. So, for example, echo !! will print out the last command run in this particular shell session.
  • "${@,,} : The construct ${foo,,} will convert the contents of the variable $foo converted to all lowercase letters. $@ is the array of positional parameters. When used inside a function, it is expanded to the parameters passed to that function.

So, "${@,,}" will simply convert whatever was passed to the function into lowercase and then execute it. Therefore, running the ?? function with !! as a parameter will convert the last command to lowercase and run it.

share|improve this answer
Perhaps you could add an explanation of how this works? It is very cryptic the way you've written it. Also, it doesn't actually work, as such. As you've written it, it will only work correctly if your PWD is empty. You need to quote the "!!". – terdon May 13 '14 at 13:34
@terdon Now, thanks to glenn, it should work in any case... And there is nothing too much to explain: the function ?? converts its arguments letters to lowercaes and !! re-write automaticaly the previous command in the current command (so ?? takes as argument the previous command). – Radu Rădeanu May 13 '14 at 17:13
`echo  !! | tr '[:upper:]' '[:lower:]'`

The key is in the ` (backticks) quotations - which runs the output as a command.

share|improve this answer
The backticks where invisible in the first version of the answer, due to the markup language. No need to downvote (without comment) for this; just edit. – Rmano May 13 '14 at 15:36
tr would be my first choice, too. Also works (alternative to backticks and without the POSIX bracket-classes) : $( echo !! | tr '[A-Z]' '[a-z]') – belacqua May 27 '14 at 21:23

here comes a programmers answer.... use python:

`echo "print '!!'.lower()" | python`

Or Ruby:

`echo "print '!!'.downcase" | ruby`

Or Perl (probably my favorite):

`perl -e "print lc('!!');"`


`php -r "print strtolower('!!');"`

Or Awk:

`echo "!!" | awk '{ print tolower($1) }'`

Or Sed:

`echo "!!" | sed 's/./\L&/g'`

Or Bash:

str="!!" ; ${str,,}

Or zsh

echo "A='!!' ; \$A:l" | zsh

Or NodeJS if you have it:

`echo "console.log('!!'.toLowerCase());" | node`

You could also use dd (but I wouldn't!):

 `echo "!!" | dd  conv=lcase 2> /dev/null`

You could also create a small script to do the job:

sudo bash -c 'cat << EOF > /usr/local/bin/lower
import fileinput
print "".join(fileinput.input()).lower(),
EOF' && sudo chmod +x /usr/local/bin/lower

Which you use like so:

`echo !! | lower`
share|improve this answer

And the one with sed,

$(echo !! | sed 's/^\(.*\)$/\L\1/g')


SUDO: command not found
$ $(echo !! | sed 's/^\(.*\)$/\L\1/g')


$(echo SUDO APT-GET UPDATE | sed 's/^\(.*\)$/\L\1/g')
[sudo] password for avinash: 
0% [Waiting for headers] [Waiting for headers] [Waiting for headers] [Connectin^
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.