Skip to content

Instantly share code, notes, and snippets.

@peteboere
Created September 2, 2011 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peteboere/1189491 to your computer and use it in GitHub Desktop.
Save peteboere/1189491 to your computer and use it in GitHub Desktop.
Batch file renaming with bash
# 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