Skip to content

Instantly share code, notes, and snippets.

@wancw
Created December 19, 2014 10:41
Show Gist options
  • Save wancw/23486e650cc8d7041d42 to your computer and use it in GitHub Desktop.
Save wancw/23486e650cc8d7041d42 to your computer and use it in GitHub Desktop.
Run rename(1) recursively
#!/bin/sh
TARGET_DIR="$1"
shift
FROM="$1"
shift
TO="$1"
shift
if [[ "$*" != "" ]]; then
RENAME_ARGS="$*"
else
RENAME_ARGS="-n"
fi
echo f d | xargs -n 1 -I = echo find "$TARGET_DIR" -type = -exec rename -e "s/$FROM/$TO/g" $RENAME_ARGS '{}' ';'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment