After coming from cygwin, I'm quite confused about the bash (version 4.1.5) globbing on my Ubuntu 10.4. I'd love one of the following two possibilities:

  • ignore . and .., match everything else
  • ignore filenames starting with a dot unless given explicitly

The current behavior is plain strange:

cd; ls .*

says "ls: cannot access .*: No such file or directory" although I explicitly asked for filenames starting with a dot.

cd; ls .gnupg/*.gpg

complains as well although I'm asking for files not starting with a dot (it's just the directory name what starts with a dot).

Output of shopt -p


The solution

I've changed shopt to values from another user (not having this problem) and it didn't help. Then I came to the idea to bisect my .bashrc and find the offending line which contained something like GLOBIGNORE='.[!/.]*:..[!/]*:*/.[!/.]*:*/..[!/]*:...

I've replaced it by GLOBIGNORE='.:..', which does nearly what I want, and it works.

  • I've never seen this behavior. Could you edit your question to include the output of shopt -p, please?
    – Arcege
    Mar 12, 2012 at 21:29
  • This behavior is very strange, indeed. I edited my question.
    – maaartinus
    Mar 12, 2012 at 23:04

3 Answers 3


Unfortunately, I must answer my own question. It was GLOBIGNORE. From the man page:

A colon-separated list of patterns defining the set of filenames to be ignored by pathname expansion. If a filename matched by a pathname expansion pattern also matches one of the patterns in GLOBIGNORE, it is removed from the list of matches.


The "ls: cannot access .*: No such file or directory" error sounds like there are permissions problems with the current directory. I can reproduce it with:

$ mkdir -p ~/tmp/tmp
$ cd ~/tmp/tmp
$ ls .*

$ chmod u-r .
$ ls .*
ls: cannot access .*: No such file or directory
$ ls -ldn .
d-wxr-xr-x 2 1000 1000 4096 2012-03-12 18:31 .
$ chmod u+r .
$ ls .*


I'd suggest running chmod +r . and trying the ls .* again.

  • That's interesting, but can't be the cause. The concerned directory is my $HOME and the permissions are right (700).
    – maaartinus
    Mar 13, 2012 at 2:29

It is more than likely that you have no files being matched by the globs. If no files are matched, bash by default interprets * literally. You may wish to set nullglob using shopt -s nullglob to avoid this (although this will leave the command barren of arguments altogether if no files are matched).

  • You're right in what you're saying about not matching. But it should match, there're tons of .foo files in my home directory, etc.
    – maaartinus
    Mar 12, 2012 at 22:09
  • 1
    At the very least, .* should match . and .., which means it should always match. Mar 13, 2012 at 0:34
  • @MatthewScharley - Ah, good point.
    – Chris Down
    Mar 13, 2012 at 3:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .