UNIX find case insensitive
I use the find
all the time to
(unsurprisingly), find files or directories I’m looking for. I prefer it to any UI built into my
OS (currently Ubuntu, but all OSes seem to have this kind of thing - Alfred/Spotlight/Start Menu
etc), because I usually know roughly where I’m looking, and I can be declarative about what I’m
looking for (e.g. file that starts with x and has the extension .blah).
Today I learned that the find
option I use all the time, -name
, has a case-insensitive version.
I can’t believe I didn’t try and guess this earlier, but that option would be -iname
. This option
has identical behaviour to the standard, but doesn’t match on case. This means that wildcards like
*
can still be used, but the terms included in the search string can be in any case - upper,
lower, or mixed.
I came across this because I was attempting to export my highlights from my Kindle. After some
research, I discovered that highlights are stored on a Kindle in documents/my-clippings.txt
.
Great! Except..I have many, many files in that folder. I first used find . -type f -name
'*clippings*'
to find it…that didnt’ match anything. I was then able to use -iname '*clipping*'
where I did find it - named “My Clippings.txt”.
Because I used the wildcard in my term, I also found an additional file I can now looking into - “My Clippings.sdr”.