tags:

views:

193

answers:

2

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?

+2  A: 

The latter command prunes . itself -- the directory you're running find against -- which is why it generates no results.

Charles Duffy
think you mean "latter"
kostmo
+3  A: 

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.

Dennis Williamson
"find is not a Bash command" - good call, changed title to reflect this
kostmo