rsync: How to exclude Dotfiles only in topmost directory?

When performing backups under Bash with rsync, I'm trying to exclude all dotfiles and hidden directories in the top directory, but not those in otherwise targeted directories. For example:

/copyme.c  
/.dontcopythisfile  
/.dontcopythisdirectory/or_its_contents  
/directory/.butcopymetoo

rsync -a --include=".includeme" --exclude=".*" . DEST fails to copy the desired dotfiles in subdirectories, but variations such as --exclude="./.*" also fail.

Suggestions? Does this require a filter rule as opposed to the simpler --exclude?


You should use anchor, and in rsync the anchor character is '/'.

So in your string should be:

rsync -a --include="/.includeme" --exclude="/.*" ./ DEST