copy file upon --delete possible?

Paul Slootman paul at
Wed Mar 28 15:03:19 GMT 2007

On Wed 28 Mar 2007, Julian wrote:
> Hi all, I have a particular request:
> I was asked whether when --delete is specified on the client, the daemon 
> can, instead of delete the file, move it to a "trash" directory.
> The path of the latter may be hardcoded and it is not important to 
> retain info about original path etc..
> Not sure whether --backup or some similar option can do this just for 
> deleted files... I was looking through the source to see if this can be 

A simple test (much easier than looking at the source :-) :

$ cd /tmp
$ mkdir x y
$ rm -rf z
$ date > y/foo
$ rsync -av --delete --backup --backup-dir=../z x/ y
building file list ... done
deleting foo

sent 77 bytes  received 26 bytes  206.00 bytes/sec
total size is 0  speedup is 0.00
$ ls -l y
total 0
$ ls -l z
total 4
-rw-r--r-- 1 paul staff 30 Mar 28 17:00 foo

So, yes, it's possible.

Paul Slootman

More information about the rsync mailing list