Skip to content

Instantly share code, notes, and snippets.

@Firxiao
Last active May 27, 2021 03:31
Show Gist options
  • Save Firxiao/052ba37bb1abb85c949a6f05539f8762 to your computer and use it in GitHub Desktop.
Save Firxiao/052ba37bb1abb85c949a6f05539f8762 to your computer and use it in GitHub Desktop.
#!/bin/bash
# rename all files and dirs name to lower case
DEST=$2
function rename()
{
name="$1"
lowerCaseName="$(echo "$name"|tr '[A-Z]' '[a-z]')"
if [ -d "$name" ]; then
if [ ! -d "$DEST/$lowerCaseName" ]; then
echo "mkdir -p $DEST/$lowerCaseName"
mkdir -p "$DEST/$lowerCaseName"
fi
elif [ -f "$name" ]; then
echo "rsync "$name" to "$DEST/$lowerCaseName""
dirPath=$(/usr/bin/dirname "$name")
mkdir -p "$DEST/$dirPath"
rsync --protect-args --size-only -avzP "$name" "$DEST/$lowerCaseName"
fi
}
function main()
{
ls "$1"|while read file;
do
if [ -d "$1/$file" ]; then
#echo "Dirs: $1/$file"
main "$1/$file"
rename "$1/$file"
else
#echo "File: $1/$file"
rename "$1/$file"
fi
done
}
if [ $# != 2 ]; then
echo "Usage: $0 source_dir dest_dir"
exit 1
fi
main "$1" "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment