I want to synchronize some files from a server to my local machine. Particularly, for each directory and sub-directories contained in the synchronized main one, among all the present files, I would like to synchronize only the one which have a certain defined name (and only the updates of it, excluding the deleting of course).

Which command do i need to be able to do that?

1 Answer 1


To only copy any file called e.g. myfile from some source to some target:

rsync -n -aim --include='myfile' --include='*/' --exclude='*' source/ target

This uses --include and --exclude to only consider your filename and any directories, but to ignore anything else. Since we're using -m, it would additionally not create directories that does not contain files called myfile.

The -n option stops anything from actually being copied, so you would test this until you are confident that it would work and then remove -n from the command. You should test this on a copy of you backed-up data.

  • It works and copy the file as I need, however if I change a file on the server, it does not change on the local as well. Moreover, why you say we are using -m? I cannot see it. Jul 9, 2021 at 11:52
  • @cmp666 If the file did not update, did you forget to remove -n from the command line? We're using -m to avoid creating/updating directory entries on the destination that does not contain files with the name we're looking for. If you're syncing against an empty destination directory, you would otherwise end up with a lot of empty directories.
    – Kusalananda
    Jul 9, 2021 at 12:08
  • thank you very much. i removed -n otherwise it would not even copy the files from the cluster to local, but still when i modify on the cluster it doesnt update on the local. do i have to run the same command every time.. or maybe it just takes some time to update? i really appreciate your help! Jul 9, 2021 at 12:14
  • i dont know how rsync checks if a file is being updated actually, maybe if you change like just a line it wont happen, it may need the size or the creation time to change. i thought it was able also to see the modification time of the file and transfer the update. is there a special flag to use for that in case is possible? Jul 9, 2021 at 12:16
  • @cmp666 By default, rsync will update a file if its modification timestamp or size changes. If you change a file in such a way that you don't modify any timestamp or the file's size, then it may skip that file. If this is the case, add the -I (--ignore-times) option to the rsync invocation.
    – Kusalananda
    Jul 9, 2021 at 12:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .