How to copy hidden files using CLI (cp and/or tar commends)

Just a quick question:

How would I copy ONLY hidden files using (a) the cp, and (b) the tar commands in the command line?

I’ve been trying to brush up on CLI a bit, but I can’t figure this one out …



cp /home/*username/.*filename <to location>

eg: from my terminal
cp /home/kernelcruncher/.xsession-errors /home/kernelcruncher/bin

Thanks, but what about copying several files? (For example, all files starting with “K”,or all hidden files in a given directory?)
In these cases, the placeholder “.*” doesn’t seem to work as all files are copied, not just the hidden ones.


Most hidden files are of the form .[A-Za-z]*, so you can use this glob:

cp .[A-Za-z]* destination-directory

If you have numeric dotfiles, then add 0-9 to the brackets.

Thanks! :slight_smile:

What about, for example, copying ALL FILES EXCEPT files 1-n? (e.g. all except .kde, .kde4)

Try a glob like: