Capitalize the first letter of every word in a filename or directory in Shell
bash, shell, unix
Solution
Using GNU Sed
You can do this quite easily with GNU sed. For example:
$ echo '/doCumenTS/tesT.txt' | sed 's!/.!\U&!g'
/DoCumenTS/TesT.txt
Limitations
Note that the \U escape is a GNU sed extension. The manual says:
Finally, as a GNU 'sed' extension, you can include a special sequence made of a backslash and one of the letters 'L', 'l', 'U', 'u', or 'E'.
`\U'
Turn the replacement to uppercase until a `\L' or `\E' is found
Problem
I'm trying to write a shell command where I can specify a directory, and then every file and directory inside will have the first letter of every word capitalized. So `/doCumenTS/tesT.txt` should change to `/DoCumenTS/TesT.txt` I'm thinking it should start like ``` for i in directory do tr something_goes_here done ``` The problem I can't figure out is how to only do the first letter. I've made a script that uppercase the whole file name, but I can't figure out how to only get the first letter of every word. Thanks!