Trying to copy archive from one network share to another while ignoring the tilde character

I've been trying to copy an archive volume from one network share to another. Because most of these files are Mac files, I am using Mac Terminal to do so. I've tried every combination of cp, rsync, and ditto that I could come up with.

The problem lies in the fact that many of these files have a similar name and every once in a while I'll come across one that has a tilde character in the file name. Depending on what variation of cp or rsync command I use, when it comes across this it either fails, stating that file already exists, or, skips the file with the tilde all together and continues on with the process.

For example: "28910 BP Umba Show.SIT" is treated as identical to "28910B~1.SIT" and therefore will not copy to the new archive location.

Any help is greatly appreciated, thanks in advance.


Solution 1:

The filename 28910B~1.SIT looks like an MS-DOS abbreviated file name that has more than the 8.3 characters (long file names).

It's important to note that from Windows 2000, both the long name and the shortened 8.3 name were retained (the file had both names)

...when an application saves a file on a computer running Windows 2000, both the 8.3 file name and long file name are retained.

For example, 28910 BP Umba Show.SIT is automatically abbreviated to 28910B~1.SIT and duplicates are incremented (28910B~2.SIT, 28910B~3.SIT, 28910B~4.SIT, etc.) You can read more about this naming convention on Microsoft Tech Network

There's a good chance it's a dupe of one of your files, but the only way to know for certain is to open both and verify.

From the comment:

Either way, I need some magic that will copy the archive and ignore the tilde.

It can't ignore the tilde - it's there and it must be dealt with; as far as macOS is concerned, the two files have identical names (because they do).

To copy both files but not overwrite the one already in the destination folder, you can to a quick test in your command to see if the file already exists in a for/do loop:

for file in /source/directory; do $time=date +%s; if [[ -f /target/directory/$file ]]; then cp $file ${file}-${time}; else cp $file /target/directory/$file; fi; done

This command will parse through your source directory, check if the file exists in the target directory, if it does it will copy the file over appending the current time in seconds (to ensure no multiple dupes); if no dupe exists, it just copies the file over.