# Copy only hidden files and directories



## alelab (Oct 7, 2010)

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.

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


----------



## SirDice (Oct 7, 2010)

Tricky.. .* also includes . (current directory) and .. (parent directory).

Try this one:

```
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 (*)


----------

