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.
--include
first, but the "./" in front of the "./.htaccess" was what was killing it. – Rich Apr 11 '11 at 18:26.htaccess
file, you'll have to--include='.*/'
(I think) before the final--exclude
, see also here – Tobias Kienzler Nov 19 '12 at 14:47rsync -avP --exclude=/.htaccess src/dir/ dst/dir/
works as expected (excludes.htaccess
only at the root directory), butrsync -avP --exclude=/.htaccess src/dir dst
doesn't (it fails to exclude even at the root)? – haridsv Mar 02 '21 at 13:53src/dir
and you're copying the root, sosrc/dir/.htaccess
is excluded. In the second case, the root issrc
and you're copyingdir
, sosrc/.htaccess
is excluded. – Gilles 'SO- stop being evil' Mar 02 '21 at 14:22rsync -avP --exclude=/dir/.htaccess src/dir dst
– haridsv Mar 03 '21 at 07:36