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 -regextype posix-extended -regex matches several names in one test

Find
~/tips/tip-find-regex-extended-names

find . -regextype posix-extended -iregex '.*\.(jpe?g|png|gif)$'

Matches file paths with one regular expression instead of several -name tests.

Several -name tests joined with -o get long. One regular expression can say the same.

find . -regextype posix-extended -iregex '.*\.(jpe?g|png|gif)$'

Unlike -name, -regex matches against the whole path, starting with ./, so the expression needs .* at the front. -iregex ignores case. The default dialect is Emacs style, where ( and | need backslashes, which is why -regextype is worth setting. Quote it so the shell does not expand it first.

Further reading: find 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