76

Files

Suppose that /foo/src contains only A.c and that /foo/dest contains both A.c and B.c. And suppose I run the following command:

rsync /foo/src/ /foo/dest

Will rsync erase B.c?

Folders

Now suppose that /foo/src contains the directory A with some files inside it and that /foo/dest contains both directories A and B, each with some files inside of them. And suppose I run the following command (the -a option includes -r, recursive):

rsync -a /foo/src/ /foo/dest

Will rsync erase B and its contents?

2
  • You need the --delete switch.
    – fideli
    Mar 18, 2014 at 23:12
  • Indeed, maybe you explicitly don't need the --delete switch - it depends what result the user wants; see answers below.
    – osullic
    Mar 6 at 19:47

1 Answer 1

85

By default, rsync does not delete files but that depends on the commands options you specify. You can use any the following if you WANT to delete files:

  • −−del (alias for −−delete−during)
  • −−delete (deletes extraneous files from dest dirs)
  • −−delete−before (receiver deletes before xfer [default])
  • −−delete−during (receiver deletes during xfer, not before)
  • −−delete−after (receiver deletes after xfer, not before)
  • −−delete−excluded (also delete excluded files from dest dirs)
  • −−max−delete=NUM (don’t delete more than NUM files)

Since you specifically called out the -a option, here's what the man page says

−a, −−archive >

This is equivalent to −rlptgoD. It is a quick way of saying you want recursion and want to preserve almost everything (with −H being a notable omission). The only exception to the above equivalence is when −−files−from is specified, in which case −r is not implied.

Note that −a does not preserve hardlinks, because finding multiply-linked files is expensive. You must separately specify −H.

So it seems the answer to your question is NO, it won't be deleted given your examples.
HTH

1
  • While this is an excellent answer, I don't think you should use the word "xfer" because, well, it's not a word. Let's make explanations easy for everyone to understand, including speakers whose native language is not English. (For anyone wondering, 'xfer' = 'transfer')
    – osullic
    Mar 6 at 19:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .