Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 am backing up data from a folder in MAC. The MAC unnecessarily creates some files startinmg with . like

.dsdfsd or ._hjdds

Now i want to exclude the files starting with . in rsync .

How can i do that

share|improve this question
up vote 5 down vote accepted

If you search in the rsync man page for "exclude", you will find:

--exclude=PATTERN exclude files matching PATTERN

So this would probably work:

rsync --exclude='.*' [other arguments]
share|improve this answer
Think exclude supports regular expressions, so you'd have to escape the '.' like `exclude='\.*'. You might also want to use an exclude file if you have a lot of conditions to match. – gravyface Apr 30 '10 at 0:46
@gravyface: No, it's similar to globbing, from the man page: "Here are some examples of exclude/include matching: “- *.o” would exclude all names matching *.o". – Dennis Williamson Apr 30 '10 at 1:07

I would replace Dennis's regex with


The ".*" pattern got me into a lot of trouble way back in my youth, when I tried to remove all of the hidden files from someone's home directory...

rm -rf .* 

Is NOT a good thing to do. (Here's a hint: .* matches ..)


Thanks to Dennis commenting on this, you can disregard my warning (though I'm leaving the comment to show that I'm doubly an idiot) ;-)

share|improve this answer
It's similar to globbing rather than a regex. In rsync, .* doesn't match .. and excluding .. is safer than including it which is what your rm did. Even an explicit include doing rsync --include '..' * dest knows that you didn't really mean it. Also, your .??* would allow (not exclude) short filenames such as .aa. (However, your point is really about good habits.) – Dennis Williamson Apr 30 '10 at 1:14
Nice, thanks! I thought rsync used regexes rather than globbing...but then there's probably a flag for that :-) I appreciate the info! – Matt Simmons Apr 30 '10 at 13:32

Your Answer


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