Rsync – Fix for –delete Option Not Deleting Files in Target Directory


I'm trying to use the --delete option in rsync to delete files in the target directory which isn't present in the original directory

Here is the command I'm using:

rsync -avz --ignore-existing --recursive --delete /var/www/*

So my question is, how can I delete all files in target directory which aren't present in the original directory?

Best Answer

Use this command:

rsync --archive --verbose --compress --ignore-existing --delete /var/www/

You do not need a "*" and should not use it too.

To exclude/include files or directories, you should use this parameters:

--exclude 'to_exclude*'
--include 'to_include*'
Related Question