How to exclude hidden file ".htaccess" in rsync?

1.7k views Asked by At

I want to exclude one special hidden file in just one special folder.

The command I used is:

rsync -a --delete                                 \
  --exclude='/absolute/path/to/webpage/folder1'   \
  --exclude='/absolute/path/to/webpage/backups'   \
  --exclude='/absolute/path/to/webpage/.htaccess' \
  /absolute/path/to/webpage/                      \
  /absolute/path/to/copy_of_webpage &>/dev/null

rsync always overwrites my .htaccess.

Also I want to keep my .htpasswd and I thought about using wildcards like:

rsync -a --delete                               \
  --exclude='/absolute/path/to/webpage/folder1' \
  --exclude='/absolute/path/to/webpage/backups' \
  --exclude='/absolute/path/to/webpage/.ht*'    \
  /absolute/path/to/webpage/                    \
  /absolute/path/to/copy_of_webpage &>/dev/null

But that doesn't work either.

2

There are 2 answers

3
Pierre Inglebert On

You could exclude all .htaccess with --exclude '.htaccess'

0
Paul Roub On

Exclude the path relative to the source folder, not the absolute path.

If your root (as above) is:

/absolute/path/to/webpage/

and you wish to exclude:

/absolute/path/to/webpage/.htaccess
/absolute/path/to/webpage/backups

then you'll need to say:

--exclude='/.htaccess' --exclude='/backups'

Per the docs:

"/foo" would match a file called "foo" at... the "root of the transfer"