How to handle spaces in paths with rsync on Linux?

The common rsync commands seems not handle spaces well. For example,

rsync -avxP file "user@server:/data/my dir"

It reports:

rsync: link_stat "/home/zma/file" failed: No such file or directory (2)

How to make rsync handle spaces well?

asked Sep 30, 2016 by anonymous

1 Answer

You can use the --protect-args option of rsync.

$ rsync --protect-args -avxP file "user@server:/data/my dir"

What does --protect-args do:

-s, --protect-args
This option sends all filenames and most options to the remote rsync without allowing the remote shell to interpret them. This means that spaces are not split in names, and any non-wildcard special characters are not translated (such as ~, $, ;, &, etc.). Wildcards are expanded on the remote host by rsync (instead of the shell doing it).


You may also control this option via the RSYNC_PROTECT_ARGS environment variable. If this variable has a non-zero value, this option will be enabled by default, otherwise it will be disabled by default.

Check rsync manual for more details.

answered Oct 3, 2016 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost