10
2
How to copy hidden files and hidden subdirectories (the ones starting with a dot) in folder A to folder B? For example if I have this structure:
A/a
A/b
A/.a
A/.b/
A/.b/somefile
A/.b/.c
I would like to copy to B just the hidden files and hidden subdirectories in A:
B/.a
B/.b/
B/.b/somefile
B/.b/.c
I have already tried this command: cp A/.* B
from this other superuser question. However, it does not copy the subdirectories. Also tried cp -r A/.* B
, but it copies .
so I end with an exact copy of A (including the normal files). Any help is appreciated.
This works for the example file and directory names given in the question, but the text of the question says “hidden files and hidden subdirectories (the ones starting with a dot)”, and this answer will not find files and directories whose names begin with two dots; e.g.,
..c
. – Scott – 2014-10-27T22:27:34.170That's quite an edge case, but a legitimate concern none-the-less. I hadn't considered that. You could account for that by switching to
.*[^.]
but then you'd miss files that end with a.
. I think you would indeed need extended globbing to truly account for all cases. – Omnipresence – 2014-10-28T13:08:34.390