Sunday, April 28, 2024
20
rated 0 times [  20] [ 0]  / answers: 1 / hits: 8584  / 3 Years ago, wed, august 4, 2021, 9:16:25

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.


More From » command-line

 Answers
1

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.


[#31707] Thursday, August 5, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
oleard

Total Points: 344
Total Questions: 105
Total Answers: 113

Location: Bonaire
Member since Tue, Sep 20, 2022
2 Years ago
;