0

How to rename a bunch of files in a directory to be param-case with the hyphen?

Here's one that does it in JavaScript, but I'm not sure how to go about this in bash.

Lance
  • 75,200
  • 93
  • 289
  • 503

1 Answers1

1

Below is an option in bash:

for file in ./* ; do mv "$file" "$(echo $file | sed 's/\(.\)\([A-Z]\)/\1-\2/g' | tr '[:upper:]' '[:lower:]')" ; done

An alternative with perl:

for file in ./* ; do mv "$file" "$(echo $file | perl -ne 'print lc(join("-", split(/(?=[A-Z])/)))')" ; done
1218985
  • 7,531
  • 2
  • 25
  • 31