The Stack Overflow podcast is back! Listen to an interview with our new CEO.
1 of 4

This answer from Alex B at Stack Overflow will help you to rename both files and subfolders under a directory.

It consists on using both find and rename Linux commands. I would only add that the command provided in the link above will modify directory names as well. In case that you want only to change file names, you need to change the -depth option with the next one: -type f so the command that you need to execute looks like below

find my_root_dir -type f -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;

Another regular expression given to the rename command could be the one below, which I think it is more easy to understand.

 find my_root_dir -type f -exec rename 'y/A-Z/a-z' {} \;

Be aware that there is a necessary white space between the rename command regular expression and the curly braces, and another one between them and the command termination character \;

Also remember that it will rename every file not only in the directory where you execute the command from (the my_root_dir directory) but also to all the files under every subfolder contained into this one. You can use the -maxdepth 0 option with the find command to force it to only apply the tests and actions to the starting-points themselves.