MacOS – Using rsync with path names containing spaces

macosrsync

I am trying to use rsync (on macOS Catalina) but have trouble with spaces in file path names. I have used -s or --protect-args but they do not do anything (when I look at the help for rsync, these options are not listed).

I am running rsync 2.6.9 in zsh. Can anyone help please?

Here is what I get when I run this rsync command:

chris@cgimac ~ % rsync -ahv /Volumes/G_5TB_general/Backup of CG-nas/mac drives/Fitness and health /Volumes/G_5TB_general/temp dump
building file list ... 
rsync: link_stat "/Volumes/G_5TB_general/Backup" failed: No such file or directory (2)
rsync: link_stat "/Users/chris/of" failed: No such file or directory (2) 
rsync: link_stat "/Users/chris/CG-nas/mac" failed: No such file or directory (2)
rsync: link_stat "/Users/chris/drives/Fitness" failed: No such file or directory (2)
rsync: link_stat "/Users/chris/and" failed: No such file or directory (2) 
rsync: link_stat "/Users/chris/health" failed: No such file or directory (2) done

I get the exact same result if I modify the command to

rsync  -ahv  ‘/Volumes/G_5TB_general/Backup of CG-nas/mac drives/Fitness and health’ ‘/Volumes/G_5TB_general/temp dump’

I have looked elsewhere and there are many examples eg st

https://www.cyberciti.biz/faq/rsync-transfer-filename-that-contains-whitespace/

where the -s (or –protect-args) option for rsync apparently work.

Best Answer

The -s option doesn't protect against arguments with spaces passed on the command line, proper quoting does

rsync -ahv "/Volumes/G_5TB_general/Backup of CG-nas/mac drives/Fitness and health" "/Volumes/G_5TB_general/temp dump"

(in your second example you seem to use typographical quotes).