0

I have a plain text file with a list of paths (about 120 of them, one per each line) that I need to rsync into a single directory, for this, I'm using this suggestion:

rsync -av `cat /path/to/file` /destination/

The issue is that the paths contain spaces that are escaped with \ so they look like this:

/path/to\ some/directory-001/
/path/to\ some/directory-003/
...
/path/to\ some/directory-120/

When I run the command above I get:

rsync: link_stat "/path/to" failed: No such file or directory (2)
rsync: link_stat "/path/to/some/directory-001/" failed: No such file or directory (2)

It works perfectly if there are no spaces in the paths. I tried wrapping the paths in double quotes, single quotes, remove the \ with or without quotes.

Please let me know if there is a way around this, I may be missing something on the actual command?

Thanks!

1 Answers1

0

You could use double quotes " to use the file/dir with spaces, for example using xargs:

$ xargs < file -L1 -I {} rsync -av "{}" /destination/

In this case, your file with the paths will be passed to xargs the one will be read line by line -L1 and use {} as the placeholder for the line.

If you would like to run things in parallel you could also use the option -P, for example, if you have 4 cores you could use something like this:

$ xargs < file -P4 -L1 -I {} rsync -av "{}" /destination/

To show full path on the source you could try something like:

$ xargs < file -L1 -I {} sh -c "echo $(pwd -P)/{}; rsync -av {} /destination/" 
nbari
  • 25,603
  • 10
  • 76
  • 131
  • This did the trick. Thank you for your help. Now the last thing I need, which may be unrelated to this question, is for rsync to show the full source path, as would like to see in which of the 120 "/directory-00X/" is rsync on, but by default rsync only shows the destination path when using --progress. Any tips on this? – Richard Pastenes Aug 10 '18 at 18:57
  • @RichardPastenes check updated answer probably could give you a hint :-) – nbari Aug 11 '18 at 05:47
  • 1
    I ended using -t so xargs will show me the current command being run, which contains the pat, using a log file with rsync and ina new window tail -f into it to see the current files being copied: `xargs -t < paths -L1 -I {} sudo rsync -a --progress "{}" /destination > rsync.log` and `tail -f rsync.log` Thanks a lot for your help @nbari – Richard Pastenes Aug 14 '18 at 04:37