Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am sync-ing up a directory that has a bunch of documents in it. Users that input documents with all manner of weird characters in their file names. I need to sync up these files from one location on Linux to another. Many times only a single file needs to be updated. When the file name contains a single quote it croaks. I need to specify user@server for the destination, otherwise it works. For example:

rsync --rsh=ssh "zz/joe's change.txt" "/somedir/y/joe's change.txt"


rsync --rsh=ssh "zz/joe's change.txt" user@server:"/somedir/y/"

also works.

But the form I wish to use:

rsync --rsh=ssh "zz/joe's change.txt" user@server:"/somedir/y/joe's change.txt"

fails with:

bash: -c: line 0: unexpected EOF while looking for matching `''
bash: -c: line 1: syntax error: unexpected end of file
rsync: connection unexpectedly closed (0 bytes read so far)
rsync error: error in rsync protocol data stream (code 12) at io.c(165)

I could use the second form (unless some nut puts a ' in the directory name), but really want to use the third form.

share|improve this question

4 Answers 4

In this case, what finally worked for me was to use the --protect-args or -s argument, and then taking the whole thing under quotes as follows:

rsync -s --rsh=ssh "zz/joe's change.txt" "user@server:/somedir/y/joe's change.txt"

Note that even the remote server and user are also under the quotes.

share|improve this answer


rsync --rsh=ssh "zz/joe's change.txt" "user@server:/somedir/y/joe's change.txt"

The " is a signal to the shell and it may not work as part of an argument.

share|improve this answer

Gleb put me on the right track. I had tried escaping inside the quotes (along with other variations on quoting and escaping the destination) and that did not work.

I have now gone back and found it will work by double escaping the destination:

rsync --rsh=ssh "zz/joe's change.txt" user@server:/somedir/y/joe\\\'s\\\ change.txt


rsync --rsh=ssh zz/joe\'s\ change.txt user@server:/somedir/y/joe\\\'s\\\ change.txt
share|improve this answer

You probably need to escape that character. From bash man page

A non-quoted backslash (\) is the escape character. It preserves the literal value of the next character that follows, with the exception of <newline>.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.