Copy only hidden files and directories

Hi,

On a FreeBSD 8.1-RELEASE Desktop PC, I want to backup all my hidden files and directories of my HOME directory.
I have tried the following command but it copy all files and directories, not only hidden.
Code:
cp -r /home/<user>/.* /home/<user>/backup_hidden/

I have searched on Google and man cp, but haven't found anything that can help me.

Edit : I hope that I post this thread in the good section.
 
Tricky.. .* also includes . (current directory) and .. (parent directory).

Try this one:
Code:
cp -r /home/<user>/.[^.]* /home/<user>/backup_hidden/

The [^.] is a character class that says "everything except a period". So you get dot(.) followed by anything that isn't dot([^.]) (excluding . and ..) followed by zero or more characters (*)
 
Back
Top