Why Unix wildcard "*" does not include ".*"? Why Unix wildcard "*" does not include ".*"? unix unix

Why Unix wildcard "*" does not include ".*"?


According to Rob Pike, the whole notion that files whose name start with a dot should be "hidden" was the result of a software bug.

In particular, he says:

First, a bad precedent was set. A lot of other lazy programmers introduced bugs by making the same simplification. Actual files beginning with periods are often skipped when they should be counted.

Second, and much worse, the idea of a "hidden" or "dot" file was created. [...]

I'm pretty sure the concept of a hidden file was an unintended consequence. It was certainly a mistake.

Historical accidents aside, it is a good conservative design decision to exclude hidden files from wildcard expansion. Otherwise commands like rm * would have the potential to do a lot more damage than what was intended by the user.


This is because files prefixed with . are normally hidden, and are not part of a normal globbing expansion. This means that you don't get messed-up globs in directories that contain control files or directories (eg .svn). When you use *, you generally intend it to expand to normal files.


From the Bash manual:

When a pattern is used for filename expansion, the character ‘.’ at the start of a filename or immediately following a slash must be matched explicitly, unless the shell option dotglob is set. When matching a file name, the slash character must always be matched explicitly. In other cases, the ‘.’ character is not treated specially.

As for the rationale, I can only guess. I imagine it's so that you don't accidentally manipulate files you didn't know existed (remember that ls doesn't display .foo).