How to match case insensitive patterns with ls?

This is actually done by your shell, not by ls.

In bash, you'd use:

shopt -s nocaseglob

and then run your command.

Or in zsh:

unsetopt CASE_GLOB

Or in yash:

set +o case-glob

and then your command.

You might want to put that into .bashrc, .zshrc or .yashrc, respectively.

Alternatively, with zsh:

setopt extendedglob
ls -d -- (#i)*abc*

(that is turn case insensitive globbing on a per-wildcard basis)

With ksh93:

ls -d -- ~(i:*abc*)

You want globbing to work different, not ls, as those are all files passed to ls by the shell.


As explained by polemon, it is the shell (not ls) that extends *abc* to a list of files. This is called Pattern Matching.

Aside from changing the whole Pattern Matching behavior to ignore case, you could use another form of pattern matching than the *. The following would do what you want in bash:

ls *[aA][bB][cC]*

From bash man:

[...] Matches any one of the enclosed characters.

This allows more fine grain matching where you could use *[aA][bB]c* to match abc or ABc but not abC or ABC. Or an example in French, where I could want to match all instances of the e character:

ls *[eéèêëEÉÈÊË]*

You can also add -i (--ignore-case) option to grep to get and the below output.

[root@localhost ~]# ls -l | grep -i abc
-rw-r--r--  1 root root    0 Feb 25 20:41 fileabc.txt
-rw-r--r--  1 root root    0 Feb 25 20:41 fileABC.txt