Created
May 24, 2012 14:57
-
-
Save liuggio/2782061 to your computer and use it in GitHub Desktop.
Bulk recursive rename dirs and files
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 | |
# $1 is the var | |
# $2 is replace from | |
# $3 is replace to | |
EXPECTED_ARGS=3 | |
E_BADARGS=65 | |
HELP=$(cat <<EOF | |
Usage with three arguments: | |
`basename $0` /var/www/path/ typo type | |
EOF | |
) | |
if [ $# -ne $EXPECTED_ARGS ] | |
then | |
echo $HELP | |
exit $E_BADARGS | |
fi | |
echo "Renaming Directory" | |
find $1 -type d -name "*$2*" | while read DIR | |
do | |
newname=`echo $DIR | sed s/$2/$3/` | |
echo $newname | |
mv "$DIR" "$newname" | |
done | |
echo "Renaming Files" | |
find $1 -type f -name "*$2*" | while read FILE | |
do | |
newname=`echo $FILE | sed s/$2/$3/` | |
echo $newname | |
mv "$FILE" "$newname" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment