Earlier today someone asked for the source code for my TypeAhead predictive-text, type-ahead, auto-complete JNLP Swing application. While trying to remember where I put it I realized I was going to have to do some case-insensitive file searching on my Mac/macOS system.
I was happy to learn that both of my favorite Unix and Linux file-finding utilities support case-insensitive file searching. Both the find command and the Mac locate
command have command-line options that provide this support.
In this short tutorial I’ll demonstrate both commands for case-insensitive file-searching on Mac and Unix/Linux systems.
Case-insensitive file searching with the locate command
For the Unix/Linux locate
command, just add the -i
flag. To search my entire filesystem for files and directories that contain the string typeahead
, just use this command:
locate -i typeahead
As mentioned, that is a case-insensitive search, so it will find all variations of typeahead
, like typeahead
, TYPEAHEAD
, TypeAhead
, etc. (This assumes that you have the locate
command installed and running.)
Case-insensitive file searching with the find command
If for some reason you can't find your files with the Linux locate
command, or your system doesn't have the locate
command installed, you can also search with the traditional Unix find
command.
Here's how I did a case-insensitive search trying to find the same typeahead
files with the find
command:
find . -type f -iname "*typeahead*"
In this example I use the -type f
option to tell find
to just look for files, and not directories. If you want to search for files and directories, leave that option off.
Note that on some systems you may also have to use the -print
option at the end of that command, like this:
find . -type f -iname "*typeahead*" -print
The key to that case-insensitive search is the use of the -iname
option, which is only one character different from the -name
option. The -iname
option is what makes the search case-insensitive.
More ‘find’ command options
Note that the Linux find
command has several more case-insensitive operators, including these, which I'm taking directly from the find command man page:
-ilname pattern Like -lname, but the match is case insensitive. If the -L option or the -follow option is in effect, this test returns false unless the symbolic link is broken. -iregex pattern Like -regex, but the match is case insensitive. -iwholename pattern Like -wholename, but the match is case insensitive.