When using the find
command, why is it that the following will successfully ignore hidden directories (those starting with a period) while matching everything else:
find . -not \( -type d -name ".?*" -prune \)
but this will not match anything at all:
find . -not \( -type d -name ".*" -prune \)
The only difference is the question mark. Shouldn't the latter command likewise detect and exclude directories beginning with a period?
The latter command prunes everything because it prunes .
- try these to see the difference:
$ ls -lad .*
.
..
.dotdir
$ ls -lad .?*
..
.dotdir
You see that in the second one, .
isn't included because it is only one character long. The glob ".?*
" includes only filenames that are at least two characters long (dot, plus any single character, non-optionally, plus any sequence of zero or more characters).
By the way, find
is not a Bash command.
The latter command prunes .
itself -- the directory you're running find
against -- which is why it generates no results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With