Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an rsync command for copying my files from dev to production. I don't want to copy the .htaccess file that's in the root of the HTML directory but, I do want to copy the few .htaccess files that are in its sub directories.

I'm using the argument --exclude .htaccess which is stopping all of the files from getting copied. The other arguments I'm including are -a --recursive --times --perms. Is it possible to configure rsync to do this?

Edit: Here is my full command:

rsync -a --recursive --times --perms \
    --exclude prop_images --exclude tracking --exclude vtours \
    --exclude .htaccess --exclude .htaccess_backup --exclude "*~" \ 
    /home/user/dev_html/* /home/user/public_html/
share|improve this question
    
Funny, using --exclude '.htaccess' should be working, if the source directory you're referencing is also the base directory. Try adding the single quotes ' to the filename. –  Alexander Janssen Oct 21 '12 at 14:39
add comment

2 Answers

up vote 3 down vote accepted

When you specify --exclude .htaccess, you are excluding any path ending in .htaccess.

To exclude only the .htaccess at the root of the transfer source, you need to --exclude /.htaccess

From the rsync manpage, some further detail and a reference to additional reading:

  • if the pattern starts with a / then it is anchored to a particular spot in the hierarchy of files, otherwise it is matched against the end of the pathname. This is similar to a leading ^ in regular expressions. Thus "/foo" would match a file named "foo" at either the "root of the transfer" (for a global rule) or in the merge-file's directory (for a per-directory rule). An unqualified "foo" would match any file or directory named "foo" anywhere in the tree because the algorithm is applied recursively from the top down; it behaves as if each path component gets a turn at being the end of the file name. Even the unanchored "sub/foo" would match at any point in the hierarchy where a "foo" was found within a directory named "sub". See the section on ANCHORING INCLUDE/EXCLUDE PATTERNS for a full discussion of how to specify a pattern that matches at the root of the transfer.
share|improve this answer
add comment

Try this option:

--exclude 'some/parts/of/path/.htaccess'

Globs are also allowed:

--exclude 'some/*/of/*/.htaccess'
share|improve this answer
add comment

Your Answer

 
discard

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.