0

I want to transform/"translate" all files in a folder from lower to uppercase. I could use a for loop to do that:

for i in ./* ; do mv $i $(echo $i | tr "a-z" "A-Z") ; done
for i in `find . -maxdepth 1 -mindepth 1` ; do mv $i $(echo $i | tr "a-z" "A-Z") ; done

But I'm wondering why tr does not work within find:

find . -maxdepth 1 -type f -exec mv {} $(echo {} | tr "a-z" "A-Z") \;

It just prints the file names once again, with changing them to upper case. Why does the find version not work?

My goal is to use find instead of a for loop.

manifestor
  • 2,473

1 Answers1

1

Use rename instead:

find . -maxdepth 1 -type f -exec rename 'y/a-z/A-Z/' {} +

The {} will not expand in your subshell.

markgraf
  • 2,860