Skip to content

Instantly share code, notes, and snippets.

@Bonno
Created February 10, 2015 09:46
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 Bonno/2351647fb163c1db7ae4 to your computer and use it in GitHub Desktop.
Save Bonno/2351647fb163c1db7ae4 to your computer and use it in GitHub Desktop.
Replace special character in all files in given location
#!/bin/bash
#FS='
#'
##strip special character: '
character="'"
replace="_"
j=`find $1 -printf "%d\n" | sort -u | tail -n 1`
j=$((j-1))
echo "Max dir depth:" $j
for (( i=0; i<=j ; i++ ))
do
##limited
#for name in `find -mindepth $i -maxdepth $i -iname "*$character*" -printf "%p\n"`
##recursive
for name in `find -iname "*$character*" -printf "%p\n"`
do
newname=`echo "$name" | tr "$character" "$replace"`
echo "$name" "$newname"
mv "$name" "$newname"
done
done
##########
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment