I used to have a Debian machine and I remember using something like:
shopt -s globstar
rename 's/changethis/tothis/' **
But maybe because my bash version (version 3.2.48(1)) is not up to date I get:
-bash: shopt: globstar: invalid shell option name
-bash: rename: command not found
What would be different way to recursively rename files and folders in OS X? (10.8.5)
I want to rename every folder and file that have the string sunshine
in it to sunset
. so the file:
post_thumbnails_sunshine
will become post_thumbnails_sunset
and r_sunshine-new
will become r_sunset-new
etc.
Rename multiple items On your Mac, select the items, then Control-click one of them. In the shortcut menu, choose Rename. In the pop-up menu below Rename Finder Items, choose to replace text in the names, add text to the names, or change the name format.
You can press and hold the Ctrl key and then click each file to rename. Or you can choose the first file, press and hold the Shift key, and then click the last file to select a group.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With