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.
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 locate command have command-line options that provide this support.Back to top
Case-insensitive file searching with the locate command
It's easy to perform a case-insensitive file search with the 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 typeaheadBack to top
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 try searching 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 . -type f -iname "*typeahead*"
(FWIW, I add the
-type f option to tell
find to just look for files, and not directories.)
Note that on some systems you may also have to use the
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
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.
There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.