MacOS – Rename when copying from case-sensitive to case-insensitive

findermacos

I have a netatalk AFP share on a case-sensitive Linux system, which contains two files whose names differ only in case, test/a.txt and test/A.txt. Copying the folder containing these files in Finder to my case-insensitive drive only gives an error

The operation can’t be completed because an item with the name “A.txt”
already exists.

Is there a way to have Finder automatically rename the conflicting files?
Or is there maybe a built-in command line tool with such an option?

I could do it manually in a shell script like below, but I'm sure there must be an easier way on a system that supports both case styles.

find $1 -type f -print | while read s ; do
    t="$2/$s"
    while [ -e $t ] ; do t="$t.dup" ; done
    cp -v "$s" "$t"
done

Best Answer

Try using rsync -b or gcp -b. Both add a tilde to the end of the filename if a file with the same name exists in the target.