-1

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?

Community
  • 1
  • 1
wojteo
  • 509
  • 1
  • 8
  • 28

3 Answers3

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
  • 223,850
  • 36
  • 205
  • 328
  • 1
    The [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
3

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,121
  • 26
  • 38
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