3

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

2 Answers 2

6

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]
2
  • 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, 2010 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". Apr 30, 2010 at 1:07
1

I would replace Dennis's regex with

--exclude='.??*'

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 ..)

[EDIT]

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) ;-)

2
  • 3
    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.) Apr 30, 2010 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! Apr 30, 2010 at 13:32

You must log in to answer this question.