Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
cat <<EOF
This utility will find <Search> string and replace it with <Replacement> string
in all files in current folder including their both filename and contents
# check if GNU rename utility exists
if [ ! -f /usr/local/bin/rename ]
echo "No GNU rename utility was found. Install it by running:"
echo "brew install rename"
echo "Enter Search string:"
read FROM
echo "Enter Replacement string:"
read TO
echo "";
echo "Renaming files..."
find . -iname "*${FROM}*" -exec echo "Renaming {}" \; -exec /usr/local/bin/rename s/$FROM/$TO/ {} \;
find . -iname "*.[m,h]" -exec echo "Replacing {}" \; -exec sed -i '' "s/${FROM}/${TO}/g" "{}" \;
echo "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment