Skip to content

Instantly share code, notes, and snippets.

@jdewit
Created May 16, 2014 19:42
Show Gist options
  • Save jdewit/72373e6629df03eeb0c0 to your computer and use it in GitHub Desktop.
Save jdewit/72373e6629df03eeb0c0 to your computer and use it in GitHub Desktop.
Rename files/folder names recursively
#!/bin/bash
# Convert filenames to lowercase
# and replace characters recursively
#####################################
if [ -z $1 ];then echo Give target directory; exit 0;fi
find "$1" -depth -name '*' | while read file ; do
directory=$(dirname "$file")
oldfilename=$(basename "$file")
newfilename=$(echo "$oldfilename" | sed 's/Skydrive/Onedrive/g')
if [ "$oldfilename" != "$newfilename" ]; then
mv -i "$directory/$oldfilename" "$directory/$newfilename"
echo ""$directory/$oldfilename" ---> "$directory/$newfilename""
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment