Skip to content

Instantly share code, notes, and snippets.

@sweetmandm
Created February 12, 2013 03:23
Show Gist options
  • Save sweetmandm/4760006 to your computer and use it in GitHub Desktop.
Save sweetmandm/4760006 to your computer and use it in GitHub Desktop.
Just a simple bash script to batch rename files: takes one or two strings as arguments, and removes or replaces all instances of that string from within all filenames in the specified directory.
# /bin/sh
#
# Replaces a string from all filenames in the sourcedir.
# If the second argument is empty, it will simply remove the string.
sourcedir="."
stringToChange="$1"
replacementString="$2"
cd "$sourcedir"
for f in *"$1"*; do
mv "$f" "${f/$stringToChange/$replacementString}";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment