Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Renamer
#!/bin/bash
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
EOF
# check if GNU rename utility exists
if [ ! -f /usr/local/bin/rename ]
then
echo "No GNU rename utility was found. Install it by running:"
echo "brew install rename"
fi
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"
#EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment