So, I have a seemingly simple issue, but so far I haven't found a solution: I want to exclude the topmost directory from an rsync, while still syncing all its children. The particular issue is that I don't have permission to modify the times of the topmost directory, but want all the children to have properly sync'd times.

The rsync command I'm using is as follows:

rsync --exclude ./ -rlptDu ./ server.example.com:/usr/local/directory/

and server.example.com:/usr/local/directory/ looks like this:

drwxrws---  5 root   staff 24576 Jul  9 15:00 .

(my local user is a member of staff)

When I run rsync, I get the following error:

rsync: failed to set times on "/usr/local/directory/.": Operation not permitted (1)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1070) [sender=3.0.9]
make: *** [pub_to_mel_internal] Error 23

This is version 3.0.9 on the local machine and 3.0.7 on the remote, both machines running Debian.

  • Are you familiar with the syntax in this example: wirespeed.xs4all.nl/mediawiki/index.php/… It allows you to include specific files/directories from an otherwise excluded directory. You might need to use an exclude file though.
    – jippie
    Jul 9, 2012 at 19:35
  • Yeah. The issue is that I can't seem to convince it to exclude the toplevel directory (specifically). I haven't had issues with mixing includes / excludes in the past, it just seems as though the toplevel is a special case. Jul 9, 2012 at 20:46

2 Answers 2


I think rsync's filter rules can't match the toplevel directory, so it's always synchronized. A workaround is to synchronize all the files inside this directory instead of the directory itself.

rsync -rlptDu -- * server.example.com:/usr/local/directory/

Add .[!.]* after * if you have dot files in the topmost directory, and ..?* if you have file names beginning with two dots.

  • 2
    Awesome, thanks! That works. The only downside of this technique is that it requires the shell to select all the files. If you have tons of files in the directory (which I don't in my case), it may choke. That could probably be fixed using xargs (although not with the --delete options). Jul 9, 2012 at 22:53
  • 1
    One problem I got with using * was that --delete did not delete any files, since they were not part of the search.
    – thomasa88
    Feb 10, 2016 at 14:33
  • @thomasa88 Please see this answer. Jul 26, 2019 at 12:56

It seems rsync can exclude the topmost directory using --files-from:

$ rsync -anv from/ to/
sending incremental file list

sent 97 bytes  received 25 bytes  244.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)
$ printf '%s\n' 'a' 'b.test' | rsync -anv --files-from=- from/ to/
building file list ... done

sent 88 bytes  received 22 bytes  220.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)

Just stumbled upon it, leaving a clue here in case it helps someone (or me in the future).

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.