Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I want to back up all the hidden files and directories in my homedir using rsync, but not the non-hidden files and directories.

For example, given this directory listing:

drwxr-xr-x   7 sophie  sophie  238 31 Mar 08:45 .
drwxr-xr-x  15 sophie  sophie  510 31 Mar 08:14 ..
-rw-r--r--   1 sophie  sophie    4 31 Mar 08:12 .foo
drwxr-xr-x   3 sophie  sophie  102 31 Mar 08:45 .hiddendir
drwxr-xr-x   4 sophie  sophie  136 31 Mar 08:13 VisibleDirectory
-rw-r--r--   1 sophie  sophie    9 31 Mar 08:13 VisibleFile

I want to back up .foo, .hiddendir, and all the contents of .hiddendir whether they are hidden or not. I don't want to back up VisibleDirectory or VisibleFile.

All the incantations I have come up with back up ".", and therefore all its contents including VisibleFile and VisibleDirectory, and I can't figure out how to exclude it. Please help!

I'm using Mac OS X 10.5.6 (Leopard) and rsync version 2.6.9 protocol version 29.

share|improve this question
up vote 5 down vote accepted

A common pattern to match the hidden items is .[^.]*

rsync -a ~/.[^.]* /path/to/backup

This copies all files starting with a single dot. Note that it doesn't include files starting with more than one dot.

share|improve this answer
    
Very helpful. I can also use rsync -a source/[^.]* dest/ to sync all the non-hidden files, excluding entries such as .git. – Sophia Feng Oct 17 '14 at 7:01

It's usually ".??*" to make sure you don't copy "." and ".."

(What if you had a file that was just ".a" ?)

share|improve this answer
    
This is right. $ rsync -a ~/.??* /path/to/backup – ashawley Mar 30 '09 at 20:21
    
Genius. Thank you! – Sophie Gage Mar 30 '09 at 21:09

Have you tried incarnations like ./.*?

Could you copy the hidden files to a temp directory, back up the temp directory, then remove it?

share|improve this answer

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.