find -regex for several extensions

I’m trying to cleanup some files on a Debian 11 machine.

These files live in a subdirectory in:

  • /tmp/.debrief, or
  • /opt/site/var/debrief

I can identify them by the extension in their filename:

  • .debsess,
  • .slmcrec,
  • .div, or
  • .debmeta

I thought using GNU findutil’s -regex flag and the -delete flag would be perfect:

find /tmp/.debrief /opt/site/var/debrief \
    -regex '.*\.(?:div|debmeta|slmcrec|debsess)' \
    -delete

But it doesn’t seem to match any of the files I see. Then I realized find doesn’t directly implement pcre:

$ find -regextype help
valid types are ‘findutils-default’, ‘ed’, ‘emacs’, ‘gnu-awk’, ‘grep’, ‘posix-awk’, 
‘awk’, ‘posix-basic’, ‘posix-egrep’, ‘egrep’, ‘posix-extended’, 
‘posix-minimal-basic’, ‘sed’.

I’m pretty sure GNU grep doesn’t implement capture groups without -E, but egrep does:

$ ls /tmp/.debrief | egrep '.*\.(div|debmeta|slmcrec|debsess)'
1R_camera.div
1R.debmeta
4Ahi_camera.div
4Ahi.debmeta
...

But find still doesn’t seem to match those files:

$ find /tmp/.debrief /opt/site/var/debrief \
    -regextype egrep \
    -regex '.*\.(div|debmeta|slmcrec|debsess)'
--no output--

My find version is find (GNU findutils) 4.8.0.

What am I missing?

Read more here: Source link