Created
September 29, 2017 00:10
-
-
Save mattiasb/c3373712f0b59a5d6463184d857aadbe to your computer and use it in GitHub Desktop.
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/bash | |
function _help-flag() { | |
[[ " ${@} " == *" --help "* ]] || [[ " ${@} " == *" -h "* ]] | |
} | |
if _help-flag "${@}" || [ $# -lt 3 ] ; then | |
echo "Usage: ${0} <STR1> <STR2> FILE..." | |
echo | |
echo "Rename a bunch of files by replacing STR1 with STR2 in their filename." | |
exit 2 | |
fi | |
str1=$1 | |
str2=$2 | |
shift 2 | |
for f in "$@"; do | |
echo "${f} => ${f/$str1/$str2}" | |
done | column -t | |
echo Proceed with renaming? [yes / no] | |
read -r answer | |
if [ "${answer}" = "yes" ]; then | |
for f in "$@"; do | |
mv "${f}" "${f/$str1/$str2}" | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment