UNIX / Linux: How to Perform Case Insensitive Search

UNIX is case-sensitive. So, if you are searching for a file, but not sure of it’s case – whether it’s uppercase, lowercase or a mix of both, fret not, it’s not that difficult.

The solution to perform a case insensitive search is to use the find command. We need to pass a few parameters to the find command though.

  • directory – starting point in the directory hierarchy for the search

  • filename – the name of the file we are searching for

If we want to search for a file called “foo.c” in the HOME directory (in my case, HOME directory is /home/ibrahim):

The above command will search all the files in my HOME directory that are named exactly as foo.c. It will not match files called “FOO.C” or “Foo.c“.

To perform a case insensitive search, we will need to change the -name parameter to -iname instead.

Below is a sample output of the find command.

To search only for files and exclude directory matches, pass “-type f” parameter to the find command.

Some variants of the find command do not support the “-iname” option. In that case, we will need to use the grep command to perform the case insensitive search.

The find command will search for all files and pipe the output to the grep command. The grep command will then filter and print all case insensitive matches to “foo.c” due to the “-i” option.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }

« Previous Article
Next Article »