Ignore/prune hidden directories with GNU find command
When using the find
command, why is it that the following will successfully ignore hidden directories (t开发者_运维技巧hose 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.
精彩评论