Ubuntu – Batch rename files to lowercase

batch-renamecommand linerename

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.

Best Answer

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

Update

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.