Created
May 24, 2021 17:20
-
-
Save glapa-grossklag/13b98c983b47698fbe329ecb4d302bf0 to your computer and use it in GitHub Desktop.
Change Extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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