Invalid argument when copying files with ? in filename on OS X

WinstonSmith asked:

I’m trying to copy files from an AFP share to an SMB share.

Several files on the AFP share have a ? in the name. If I try to copy them, I get invalid argument’.

I don’t know how the files got the ? in the name in the first place.

Here is an example:

user$ cp tes?t /mnt/share/
cp: tes?t: invalid argument

I have tried to rename the file, but I get a ‘resource busy’ error message.

What can I do so that I can copy the files?

My answer:

The ? symbols represent unrecognized characters.

Most likely the problem here is that AFP uses UTF-8 filenames, but you are not logged in to the system that mounted the AFP share using a UTF-8 locale. If it’s a Linux box, you can check your locale using the locale command.

If you find it’s not using a UTF-8 locale, you can temporarily change the locale with something like:

export LC_ALL="en_US.UTF-8"

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.