ME:: find is often easier to use with shell pattern matching instead of regular expressions ; How to randomly open a jpeg or JPG or JPEG or jpg file ; explainshell.com `-iname` to do filename case insensitive pattern matching and `-o` for boolean OR
Discovered: Nov 3, 2025 18:37 (UTC) ME:: find is often easier to use with shell pattern matching instead of regular expressions! ; How to randomly open a jpeg or JPG or JPEG or jpg file ; explainshell.com - find . -type f ( -iname “.jpg” -o -iname “.jpeg” ) ¦ sort -R ¦ head -1 ¦ xargs -n 1 open
Key Details
- shell pattern matching seems (not sure how up to date this is) to be documented in gnu’s docs at 2.3.4 Shell Pattern Matching and Peter Seebach’s Patterns and string processing in shell scripts
- you can use regular expressions in find using the
-regex(probably want to also use-Eforextended modern regular expressions) and if you do regular expressions test with an online simulator like regex101 - case insensitive shell pattern
-iname pattern
Like -name, but the match is case insensitive. For example, the patterns
fo*' andF??’ match the file namesFoo',FOO’,foo',fOo’, etc. In these patterns, unlike filename expansion by the shell, an initial ‘.’ can be matched by*'. That is, find -name *bar will match the file.foobar’. Please note that you should quote patterns as a matter of course, otherwise the shell will expand any wildcard characters in them.
- within a shell pattern,
-omeansOR,-ameansAND