use of * in file searching

When you do ls * the * is being expanded before it is passed to ls. That is to say if we have three files (a, b and c) in a directory ls * is actually running ls a b c.

When Bash can't expand, it passes through the raw string¹. That's why you see the wildcards in the error, along with a not found message. ls tried to show the listing for a file literally called *.bash*.

So why didn't that expand? Well by default globbing (what this wildcard expansion is called) won't return hidden files. You can change this with shopt -s dotglob (that won't persist unless you stick it in your .bashrc — it might be disabled by default for a good reason so be careful with it), here's a quick demo:

$ ls  *.bash*
ls: cannot access *.bash*: No such file or directory
$ shopt -s dotglob
$ ls  *.bash*
.bash_aliases  .bash_history  .bash_logout  .bashrc  .bashrc.save

The exception to this is —as you've already shown— when you've already explicitly stated the files will be hidden with a pattern like .bash*. It simply overrides the default dotglob setting:

$ shopt -u dotglob  # unset dotglob
$ ls .bash*
.bash_aliases  .bash_history  .bash_logout  .bashrc  .bashrc.save

Anyway besides that quirk, I hope this helps you understand what's going on under the surface.


There are other shopt flags that alter how globbing works: extglob, failglob, globstar, nocaseglob and nullglob. They and a raft of other shopt flags are documented as part of the Bash manual.

Similarly, the page on Pattern Matching should make for some good reading.

¹ Unless failglob or nullglob are set.