I sometimes have the problem that rsync tries to transfer a new file from the source to the destination (both have the same space) when there's already not enough space left, which causes this error message:

rsync: write failed on "{FILE}": No space left on device (28)

However, there would be space left, if the files that don't exist in the source directory anymore would be deleted in the destination before any files where transfered. I'm using --delete (with the default --delete-before), but it only deletes a file right before transferring the updated version.

So, I wonder, how can I delete all the obsolete files first (using bash or rsync)?

1 Answer 1


The --delete flag to rsync will cause files in the destination directory that don't appear in the source directory to be deleted. The default behavior is to delete before transferring files. (--delete-before)

When in incremental recursion mode (the default mode since rsync version 3.0), rsync processes directories incrementally and the "delete before" only happens on a per-directory basis. It will delete files, then copy new files in the each subdirectory it finds as it encounters them.

If you want it to delete all the files to be deleted through the directory tree before doing any copying, then you need to also turn off incremental recursion mode with the flag:


Note that this will cause it to revert to the former behavior of collecting the lists of files from the entire directory tree on both sides of the transfer, doing all the applicable deletes, and then doing all the copies. This can take longer if you have a very large directory structure, but the behavior will be correct.

  • Yes, but it's only deleting that single file just before the updated version is transferred. So, if rsync is at some point copying a completely new file to the destination, the destination directory could already be quite full.
    – Joschua
    Jun 15, 2015 at 19:22
  • It was not clear from your question that you were already trying to use the --delete flag. You may also need the --no-i-r flag. This will force is to do all of the directory comparisons first. In (now default) incremental mode, it will not know to do the deletions for other parts of the directory structure until it gets to them, at which point it may have already copied other files.
    – wojtow
    Jun 15, 2015 at 19:37
  • Sorry, I updated my question. I'm not sure I understood your comment about the --no-i-r flag, but if this is an answer to my question, please update your actual answer.
    – Joschua
    Jun 15, 2015 at 19:43
  • answer updated, please let me know if the new explanation in the answer is not clear
    – wojtow
    Jun 15, 2015 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.