How to rename folders and files recursively in MacOS How to rename folders and files recursively in MacOS bash bash

How to rename folders and files recursively in MacOS


 find . -depth -name "*from_stuff*" -execdir sh -c 'mv {} $(echo {} | sed "s/from_stuff/to_stuff/")' \;


This should do the trick:

find . -name '*sunshine*' | while read f; do mv "$f" "${f//sunshine/sunset}"; done

*to specifically rename only files use -type f, for directories use -type d


You can use regular expression in the find command as stated @mbratch in the comments. You could use -regex, -iregex and -regextype to provide a complete expression to find. Then invoke -exec mv {} + (note the + sign).