# Macos – Does rsync delete files, folders at destination by default

bashmacosrsyncunix

## 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?

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