I have 2 dirs: src and dst. Src contains only 1 file "index.php". Dst contains "index.php" AND "readme.txt". I also have a list.txt file, which contains only one line: "index.php".

Now, being in the directory that contains both src and dst, I execute the following command:

rsync -av --include-from=list.txt src/ dst/ --del  

It updates the "index.php" file if it needs to, BUT it also deletes readme.txt.

Why does it delete it, if it's not in the list.txt file? Any simple way to "fix" this behavior?

What I basically want is to make rsync only care about the files from the list. They can either need updating or deleting (thus the --del option), but I don't want it to touch other files. I can't use the "--files-from" option because it doesn't delete files in the destination.

EDIT: "index.php" was just an example here - in fact too simple example, because src and dst may contain whole directory trees, so if list.txt has an entry like "abc/test.php" it should also work for this file.

2 Answers 2


The solution is to add --exclude=*:

 rsync --verbose  -r --del --include-from=list.txt --exclude=* src/ dst/

Will update only files from list.txt and delete from dst only if they are absent in src and are included in list.txt.

  • I tried that too - it doesn't delete readme.txt, BUT it also doesn't update any other file. Seems like no action is performed at all (tried on Ubuntu 12.04 & 14.04, both 64-bit). Add -v and you'll see a message like "[sender] hiding file readme.txt because of pattern *"
    – wanson
    Oct 28, 2014 at 8:41
  • Sorry, please disregard my previous comment - your answer IS correct. My file list.txt was generated by find and all files had ./ as prefix - it didn't work because of that.
    – wanson
    Oct 28, 2014 at 9:12
  • Sorry again, I have to withdraw my acceptance of this answer - I've added a clarification to my original question. Your solution doesn't seem to work for files in subdirectories - for abc/test.php rsync says: "[sender] hiding directory abc because of pattern *" and it won't update abc/test.php
    – wanson
    Oct 28, 2014 at 19:58

This may seem like an overkill, however, it worked for me:

rsync -r -av --include-from=list.txt --files-from=list.txt --delete-missing-args src/ dst/

however, it would specifically update the file depending on which one was updated/deleted.

i.e. If a file of the same name is in a different sub-directory, it will not change or delete, only will change or delete according on where it is within the src/ parent-directory.

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.