How to Match Case Insensitive Patterns with ls

case sensitivitylsshellwildcards

I would like to list all files matching a certain pattern while ignoring the case.

For example, I run the following commands:

ls *abc*

I want to see all the files that have "abc" as a part of the file name, ignoring the case, like

-rw-r--r-- 1 mtk mtk 0 Sep 21 08:12 file1abc.txt
-rw-r--r-- 1 mtk mtk 0 Sep 21 08:12 file2ABC.txt

Note

I have searched the man page for case, but couldn't find anything.

Best Answer

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.