1

1)

echo *

Only displays file names having [a-z, A-Z] but does not display files starting with .

For example .bashrc is not covered with shell glob *

2)

echo .* gives the expected output.


In first case, why does the shell glob does not include file names with dot?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
overexchange
  • 1,466
  • 10
  • 29
  • 46
  • 1
    For the why, see the history of it here: https://unix.stackexchange.com/questions/88875/why-are-filenames-that-start-with-a-dot-hidden-can-i-hide-files-without-using-a – ilkkachu Apr 21 '17 at 09:52
  • 2
    Related: [What is the setting in bash for globbing, to control whether * matches dot files](https://unix.stackexchange.com/q/40662/86440). – Stephen Kitt Apr 21 '17 at 09:53
  • 2
    and you don't need to have letters in file names... `123` and `--` are valid file names and match the `*` – ilkkachu Apr 21 '17 at 09:54
  • This is how hidden files do hide. Without it they couldn't be called hidden. – VPfB Apr 21 '17 at 11:57
  • @VPfB there’s more to it than that, consider `ls` with no arguments for example. – Stephen Kitt Apr 21 '17 at 13:02

1 Answers1

6

That’s just the way globbing works, by default (in general, not just in shells). As per the glob(7) manpage:

Pathnames

[...]

If a filename starts with a '.', this character must be matched explicitly. (Thus, rm * will not remove .profile, and tar c * will not archive all your files; tar c . is better.)

See also the relevant section of POSIX.

There are shell settings you can use to change this, or globbing modifiers in some shells that you can add to change the behaviour temporarily; see What is the setting in bash for globbing, to control whether * matches dot files for more details.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164