Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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?

share|improve this question

migrated from Sep 11 '11 at 8:34

This question came from our site for professional and enthusiast programmers.

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

So in your string should be:

rsync -a --include="/.includeme" --exclude="/.*" ./ DEST
share|improve this answer

I usually prefer to create .rsync-filter files containing the patterns:

- /.*

That way,

rsync -hxDPavilyzHFF --stats --delete ./ remote:/backup/

is the ideal backup command. The filtering is done by the -FF flags.

Note that using this method, you can have various .rsync-filter files in various subdirectories, applying to their respective subtrees. You can override exclusions in subdirectories as well, using this method.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.