brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: find -iname matches file names whatever their upper and lower case

Find
~/tips/tip-find-iname-case-insensitive

find /mnt/user/photos -iname '*.jpg'

Finds files by name while ignoring upper and lower case, so .JPG and .jpg both match.

Camera files are a mess when it comes to case. One device writes IMG_0412.JPG, an app exports holiday.jpg, and an iPhone like my iPhone 17 hands out .HEIC files. find -name '*.jpg' only catches the lowercase ones and quietly skips the rest.

The fix is one letter:

find /mnt/user/photos -iname '*.jpg'

-iname works like -name, but the match ignores case, so *.jpg matches .jpg, .JPG and even .Jpg. Combine a few of them with -o and you can grab every photo type at once. The parentheses need a backslash so the shell leaves them alone:

find /mnt/user/photos -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.heic' \) | wc -l

That counts every JPEG and HEIC file in the folder, whatever case the camera picked. Without the parentheses, -type f only applies to the first test, which is one of those find surprises you only make once.

The caveat: -iname only looks at the file name itself, not the folders above it. If you want to match on a part of the path in any case, there’s -ipath, and -iregex for a regular expression. And quote the pattern, always. Without quotes, the shell may expand *.jpg into the files in your current folder before find even starts, and then you’re searching for something else entirely.

Further reading: find(1) manual page

More Find tips find / -maxdepth 1 -fstype proc find /backup -name '*.gz' ! -exec gzip -t {} \; -print 2>/dev/null find /srv/downloads -type f -size +100M -size -1G -exec ls -lh {} + find /srv/data -depth -print find /srv -xdev -samefile /srv/downloads/movie.mkv All Find tips (46) All topics

Link