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

Is there a way to rename all files in a directory to lowercase|uppercase?

I am looking for a oneliner command.

I loved TotalCommander's alt+f7, now I need that functionality in the Terminal

share|improve this question
up vote 17 down vote accepted

For each file a_file in current directory rename a_file to lower case.

for a_file in *;do mv -v $a_file `echo $a_file | tr [:upper:] [:lower:]` ;done;

For upper case reverse the arguments to [:lower:] [:upper:]

tr command reference link


For even more control * can be replaced with ls.

For example in a directory containing 1.txt, 2.txt, 3.txt, 1.jpg, 2.jpg and 3.jpg in order to filter only *.jpg files, ls can be used:

for a_file in $(ls *.jpg);do mv -v $a_file `echo $a_file | tr [:upper:] [:lower:]` ;done;

The above code will assign to a_file variable all files with .jpg extension.

Update added -v option to mv command as per sds suggested.

share|improve this answer
+1 very slick answer! – Aaron Apr 18 '13 at 13:05
you might want to pass "-v" to mv so that you see what is being done; you might not want to pass "-f" because this may clobber existing files – sds Apr 18 '13 at 14:33
This does not work for files with spaces in their name. – Tianxiang Xiong Feb 17 at 5:03
You can use quotes around the filename. – Stef K Feb 17 at 6:26
Sorry, but the part about ls *jpg is a bad idea. You can achive the same result with *jpg along where you had * in the first place. – tink Mar 17 at 23:43

There's a more elegant and general utility called prename.

Written by Larry Wall, it comes with perl so it is most likely already available on your system as /usr/bin/prename (if you have setup alternatives is may also be available as /usr/bin/rename symlinked via /etc/alternatives to prename)

Using it you can rename multiple files in one command by providing any perl expression (including but not limited to substitution s/// or char transliteration tr///):


# Lowercase all *.JPG filenames:
prename tr/A-Z/a-z/ *.JPG

# Change any 'No' in a filename to a 'Yes':
prename s/No/Yes/g *No*

# increment first sequence of digits in a filename by 3:
prename 's/([0-9]+)/$1+3/e' *[0-9]*

# If a file contains 'aaa', append '.bak' to its name
prename 'if (/aaa/) {$_ .= ".bak"}'  *

And so on.

Another nice thing about prename is that it protects you, in the case of renaming a file to an existing file name.

man prename for more details.

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.