rsync – Fixing ‘Cannot Delete Non-Empty Directory’ Errors with –force

deletinggentoomanrsync

When running this command:

$ sudo rsync -r --delete --force --checksum --exclude=uploads /data/prep/* /data/app/

I'm getting the following output:

cannot delete non-empty directory: html/js/ckeditor/_source/plugins/uicolor/yui
cannot delete non-empty directory: html/js/ckeditor/_source/plugins/uicolor/yui
cannot delete non-empty directory: html/js/ckeditor/_source/plugins/uicolor
cannot delete non-empty directory: html/js/ckeditor/_source/plugins/uicolor
cannot delete non-empty directory: html/js/ckeditor/_source/plugins
cannot delete non-empty directory: html/js/ckeditor/_source/plugins
cannot delete non-empty directory: html/js/ckeditor/_source
cannot delete non-empty directory: html/js/ckeditor/_samples
cannot delete non-empty directory: html/js/ckeditor/plugins/uicolor/yui
cannot delete non-empty directory: html/js/ckeditor/plugins/uicolor/yui
cannot delete non-empty directory: html/js/ckeditor/plugins/uicolor

From reading the man rsync it was my impression that the --force option would tell rsync to delete these non-empty directories, which is the desired result.

Ref:

--force                 force deletion of dirs even if not empty

How can I modify the command to delete the non-empty directories?

I'm using rsync version 3.0.8, on Gentoo Base System release 2.0.3, in case that's relevant.

Update: Added sudo to the command to make it clear that this is not a file permissions issue.

Best Answer

Did you try to add --delete-excluded?

If you delete a directory in your excluded folders on the "remote" side, rsync --delete will not delete the excluded folder on your "local" site.