3

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)

2 Answers 2

4

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.

0
1

Short reason: the string ./.ignoramus is not matching .ignoramus.

Short solution: use GLOBIGNORE=*ignoramus (also read detail at the end).

$ GLOBIGNORE=*ignoramus
$ ls .* | grep ignor                 ### empty
$ ls ./.* | grep ignor               ### also empty

The asterisk will match anything (even an slash / before the name).
Of course, that will also match foobar.ignoramus. For a couple of workarounds read at the end.


Expanded answer:

That also happens with a normal file:

$ mkdir /tmp/mytest; cd /tmp/mytest
$ touch f1 f2 filetotest
$ GLOBIGNORE=filetotest
$ ls -1
f1
f2
filetotest

$ ls -1 f*
f1
f2

$ ls -1 *
f1
f2

$ ls -1 ./f*
./f1
./f2
./filetotest

GLOBIGNORE will not match ./filetotest, but if we use:

$ GLOBIGNORE="*filetotest"
$ ls -1 ./f*
./f1
./f2

$ ls -1 ./*
./f1
./f2

$ ls -1
f1
f2
filetotest

The pattern in GLOBIGNORE will match (something)filetotest.

For your example:

$ touch .ignoramus
$ GLOBIGNORE='*ignoramus'
ls -1a
.
..
f1
f2
filetotest
.ignoramus

$ ls .* | grep ignor
$ ls ./.* | grep ignor

Even with some path in front of file, it works:

$ GLOBIGNORE='*ignoramus:*filetotest'
$ mkdir -p long/dir/to/test
$ touch long/dir/to/test/{f3,f4,.ignoramus,.other,filetotest}

$ ls -1 long/dir/to/test/f*
long/dir/to/test/f3
long/dir/to/test/f4

$ ls -1 long/dir/to/test/.[^.]*
long/dir/to/test/.other

$ shopt -s dotglob
$ ls -1 long/dir/to/test/*
long/dir/to/test/f3
long/dir/to/test/f4
long/dir/to/test/.other

$ unset GLOBIGNORE; shopt -s dotglob
$ ls -1 long/dir/to/test/*
long/dir/to/test/f3
long/dir/to/test/f4
long/dir/to/test/filetotest
long/dir/to/test/.ignoramus
long/dir/to/test/.other

Of course, that will also match bar.ignoramus. If that is not desired, use:

$ GLOBIGNORE=.ignoramus:./.ignoramus

Or, if you want any path included:

$ GLOBIGNORE=.ignoramus:*/.ignoramus

You must log in to answer this question.

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