tags:

views:

1160

answers:

3

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.

+1  A: 

Have you tried incarnations like ./.*?

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

Tom Ritter
+4  A: 

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

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

Martin Beckett
This is right. $ rsync -a ~/.??* /path/to/backup
ashawley
Genius. Thank you!
Sophie Tatham
+1  A: 

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

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