Skip to content

Instantly share code, notes, and snippets.

@glapa-grossklag
Created May 24, 2021 17:20
Show Gist options
  • Save glapa-grossklag/13b98c983b47698fbe329ecb4d302bf0 to your computer and use it in GitHub Desktop.
Save glapa-grossklag/13b98c983b47698fbe329ecb4d302bf0 to your computer and use it in GitHub Desktop.
Change Extensions
#!/bin/sh
# Search recursively for all files with the extension of the first argument.
# Replace them with the extension of the second argument.
if [ "$#" -ne 2 ]; then
echo "Usage:"
echo " $0 <from> <to>"
exit 1
fi
FROM=$1
TO=$2
read -r -p "Convert all *.${FROM} to *.${TO}? [y/N] " input
case "${input}" in
[yY])
for f in $(find . -name "*.${FROM}"); do
mv --verbose -- "$f" "${f%.${FROM}}.${TO}"
done
;;
[nN])
exit 0
;;
*)
echo "Invalid option: ${input}"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment