17

I am able to successfully RSYNC over SSH as long as the paths do not have spaces in them.

When the path does have spaces, it does not work. I have tried slashes, quotes, and double quotes.

When I use slashes, the output states that it is a success but I do not see any transferred files.

rsync -avz /path\ with\ spaces/ user@remotelocation:/media/another\ path\ with/spaces/

When I use single or double quotes, it tells me that permission is denied after entering my password

rsync -avz '/path with spaces/' 'user@remotelocation:/media/another path with/spaces/'

What can I do?

Thank you.

12

Expanding on rzr's answer with example code and references, just add the -s flag, quote the paths, and don't worry about escaping spaces in the remote path:

rsync -avzs '/path with spaces/' 'user@remotelocation:/media/another path with/spaces/'

For reference, the options specified by the OP:

  • -a, archive mode, equals -rlptgoD (no -H,-A,-X)
    • Includes:
    • -r, --recursive, recurse into directories
    • -l, --links, copy symlinks as symlinks
    • -p, --perms, preserve permissions
    • -t, --times, preserve modification times
    • -g, --group, preserve group
    • -o, --owner, preserve owner (super-user only)
    • -devices, preserve device files (super-user only)
    • -specials, preserve special files
  • -v, --verbose, increase verbosity
  • -z, --compress, compress file data during the transfer

The additional parameter needed:

  • -s, --protect-args, no space-splitting, wildcard chars only
13

You need to escape spaces in both local shell and remote shell. Try this:

rsync -avz '/path with spaces/' 'user@remotelocation:/media/another\ path\ with/spaces/'

The source, /path with spaces/ in the local shell can be escaped only via putting single quotes around it i.e. '/path with spaces/'.

On the other hand in case of the destination, the local shell is escaped by putting single quotes and the spaces are escaped in the remote shell by using escape character (\) in front of the spaces.

  • 3
    Just to emphasize - you need BOTH quotes and backslashes. – Sridhar Sarnobat Apr 14 '16 at 17:34
2

look at rsync option –protect-args (-s), no extra slashes needed

  • 1
    Your answer would be much improved if you would provide an example that the novice user could follow. Thank you! – Elder Geek Jun 8 '15 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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