Rename all file names from uppercase to lowercase characters - LinuxConfig.org

This command renames all files in your current working directory from uppercase to lowercase. Make sure to use -i with mv command so you do not accidentally overwrite some of your files. On a Linux command line File and file are two distinct files. If you move/rename File to a new filename file you overwrite your current existing file.


This is a companion discussion topic for the original entry at https://linuxconfig.org/rename-all-files-from-uppercase-to-lowercase-characters

NOTE: SOME OF THE POSTS BELOW ARE TRANSFERRED FROM LINUXCONFIG DISQUS COMMENTS.

chorna_kiwka

Thank you! Save me time today

Carmin

ls | sed -n 's/.*/mv "&" $(tr "[A-Z]" "[a-z]" <<< "&")/p' | bash

This beautiful 64 character command eases verification of each step. Full abilities of ls and sed are easily maximized. I highly recommend the study of sed. I frequently batch rename files using ls|sed|bash.

Complete explanation:

ls List directory.
| Bash send output of previous command (ls) to the next command. note: ls sets -1, one file-name per line, when output is not to interactive terminal.
sed Single line at a time steam editor.
-n Sed should not repeat input lines as received.
' Bash begin append of forced single parameter to be sent to current command (sed).
s Sed substitute.
/ Sed begin search patten (almost any non-sed-command character will do)
.* Sed regex match any character any number of times.
/ Sed begin replacement pattern (same character used to indicate beginning of search pattern)
mv Move srce-file-name dest-file-name
"&" Sed character sequence found (quotes send as a single parameter to mv).
$( Bash begin a child process, to send its output to the current bash input stream.
tr Translate these-characters to-those-characters.
"[A-Z]" Tr search for ascII characters A-Z.
"[a-z]" Tr replace finds with relative ascII charcters a-z.
<<< Bash send input stream to the standard input of the current command (tr).
"&" Sed actual sequence found by sed (quotes segregate region to send to standard input of tr).
) Bash end child process (tr), sending its output stream to the bash input steam.
/ Sed end replacement pattern (same character used to begin replacement pattern).
p Sed print the result after replacement.
' Bash end forcing single parameter to sent to current command (sed).
| Bash Pipe the move commands generated from sed, into the next command
bash Bash execute the input stream of bash commands like any shell script (no need for #/bin/bash).

ls | sed -n 's/.*/mv "&" $(tr "[A-Z]" "[a-z]" <<< "&")/p' | bash

Parminder Singh

Great !! its working fine, Thank You

Red Cricket

awesome! thank you!

Hi @Carmin I have to say that is a pretty slick script. Had to wrack my brain a bit to understand its flow of execution.

A similar script without sed:
for file in $(ls); do mv -i ${file} ${file,,}; done

Not work for cyrillic chars

Hi,

Try the following:

$ ls
lubos  ľuboš
$ for i in $( ls ); do mv -i $i `echo $i | PERLIO=:utf8 perl -pe '$_=uc'`; done
$ ls
LUBOS  ĽUBOŠ

Hope this helps…

Lubos