Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I'm trying to set up an rsync that excludes all .* files except for .htaccess but unfortunately, this doesn't work:

rsync -avP --exclude=".*" --include="./.htaccess" ./. user@server:/dir

Is it possible to somehow exclude general exclude rules?

share|improve this question
up vote 14 down vote accepted

The first matching rule applies, so include .htaccess before excluding .*.

rsync -avP --include=".htaccess" --exclude=".*" . user@server:/dir

This copies .htaccess at every level. I don't know what you intended with ./.htaccess; if you want to match a file at the root of the copy only, start the pattern with a /. If you only want the root .htaccess, you can't just use --include='/.htaccess' --exclude='.*', because the non-rooted rule actually takes precedence here, you need to do something more complicated:

rsync -avP --exclude='/*/**/.htaccess' --include='.htaccess' --exclude=".*" . user@server:/dir

Further reading: basic principles for rsync filters.

share|improve this answer
@fred.bear: That one was a genuine typo, and a nasty one. Thanks for spotting it! – Gilles Apr 11 '11 at 12:22
Thanks, I had tried putting the --include first, but the "./" in front of the "./.htaccess" was what was killing it. – Rich Apr 11 '11 at 18:26
@Rich note that if there are hidden directories that contain a .htaccess file, you'll have to --include='.*/' (I think) before the final --exclude, see also here – Tobias Kienzler Nov 19 '12 at 14:47

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.