Bash – Why does ls .* show different files than ls ./.*

bashwildcards

Blank file .ignoramus in current directory exists.

bojan@localhost:~$ echo $GLOBIGNORE
.ignoramus
bojan@localhost:~$ ls .* | grep ignor
bojan@localhost:~$ ls ./.* | grep ignor
./.ignoramus

tools used
ls (GNU coreutils) 8.23
GNU bash, version 4.3.42(1)-release (x86_64-pc-linux-gnu)

Best Answer

The $GLOBIGNORE setting is processed by the shell when it expands the wildcard in your command line. In your first case, the shell first expands .* to .ignoramus, which is matched by $GLOBIGNORE, so it is not included in the names passed to ls.

In your second case, the shell expands ./.* to ./.ignoramus, which is not matched by $GLOBIGNORE. If you set $GLOBIGNORE to .ignoramus:./.ignoramus then the behaviour of your second command will match your first.

Related Question