Created
September 2, 2011 18:52
-
-
Save peteboere/1189491 to your computer and use it in GitHub Desktop.
Batch file renaming with bash
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
# Name: | |
# batchrename | |
# | |
# Synopsis: | |
# batchrename SEARCH [REPLACE] | |
# | |
# Description: | |
# Bash file renaming function. Can accept regular expression arguments | |
function batchrename { | |
search=$1 | |
replace=$2 | |
for f in *; do | |
newname=$( echo $f | eval sed "s/$search/$replace/" ) | |
if [ $newname != $f ]; then | |
mv $f $newname | |
echo "Renaming $f => $newname" | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment