I have a file that rsync uses as --files-from:


I want to be able to put comments above each dir entry like that:

# my dir1 comment

#dir2 comment

#yet another comment

but rsync complains "No such file or directory"

So far I have tried #,//,--,,SPACE

Is there a way to comment out/disable entries?

  • I am not aware of any commenting mechanism for the files-from file.
    – jw013
    Dec 14 '12 at 17:49

According to the man page on rsync:

"...Blank lines in FILE and lines starting with ’;’ or ’#’ are ignored..."

I just ran a quick test and indeed # and ; lines are ignored.

  • I can't seconds the ; but the # (looking here, searching ‚when rules are...‘). → So arguably # is a bit safer... Feb 19 '17 at 14:42
  • Not in this rSync man page: linux.die.net/man/1/rsync , neither in this other: ss64.com/bash/rsync.html. Could you please refer yours? Apr 1 '17 at 20:33
  • 2
    Your page does indeed show that lines starting with # are comments: linux.die.net/man/1/rsync indicates "...When rules are being read from a file, empty lines are ignored, as are comment lines that start with a lq#rq. ..." (lq and rq are notation for left quote and right quote...I don't know why that Web page renders quotes as these abbreviations). Regardless, # in an rsync exclude file are comments. Perhaps the other man page you reference is simply old. You can review the rsync log history here: git.samba.org/?p=rsync.git;a=log
    – rob_7cc
    Jun 9 '17 at 1:12
  • The best thing to do is to look at the man page on the platform where you are developing to determine the version of rsync you are using; you can search the man page for how comments are handled by that version of rsync.
    – rob_7cc
    Jun 9 '17 at 3:48

Do a grep -v '^#' file > /tmp/filetmp and then launch your rsync on /tmp/filetmp

Depending on your shell, you may be able to avoid the temporary file (this is valid in Bash):

rsync --files-from <(grep -v '^#' file) …

The weird-looking <( … ) syntax is what Bash calls process substitution.

  • 3
    I added the pattern to your grep for you—I assume this is what you meant... I'm going to add in a bash trick as well, feel free to revert one or both edits if you disagree.
    – derobert
    Dec 14 '12 at 18:32
  • You may use --files-from=- to have rsync read the list from standard input.
    – Kusalananda
    Oct 30 '17 at 16:59

state for now (rsync version 3.1.1 protocol version 31): all lines starting from # or ; are ignored even man have no information about that (my case was different, I wanted to copy a file named ;_char and was surprised that wasn't even using --from0 option - after changing line to ./;_char it started to work). Seems that the same parsing function is used as for options --include-from or --exclude-from For these two options man page mention: Blank lines in the file and lines starting with ’;’ or ’#’ are ignored

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.