I need to change all names of all files in specific directory to lowercases, using bash script. Moreover I don't want to change names of subdirectories, as it was proposed in How to rename all folders and files to lowercase on Linux?
Asked
Active
Viewed 3,024 times
3 Answers
4
Try this:
for file in * ; do lower=$(echo $file | tr A-Z a-z) && [[ $lower != $file ]] && echo mv $file $lower ;done
It will echo the commands you need to run. Check them first, then you can remove the echo and run it again to do the actual moves

Jakub Kotowski
- 7,411
- 29
- 38
4
for file in *; do
[[ -f "$file" ]] && mv "$file" "${file,,}" 2>/dev/null
done
I'm not sure what version of bash introduced the ${var,,}
expansion.

glenn jackman
- 238,783
- 38
- 220
- 352
-
1The [release notes](http://tiswww.case.edu/php/chet/bash/NEWS) have it as item hh for version 4.0. – chepner Jan 14 '14 at 17:36
0
Try the following:
for i in $(find . -maxdepth 1 -type f -name "*[A-Z]*"); do mv "$i" "$(echo $i | tr A-Z a-z)"; done
[1] refer

Community
- 1
- 1

Mitesh Pathak
- 1,306
- 10
- 14
-
2This is not a safe way to iterate over files: if you find a filename with a space, the for loop will not treat it as a single word. – glenn jackman Jan 14 '14 at 17:13