2

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?


Edit: Output of egrep per request in the comments:

$ ls /tmp/.debrief | egrep '.*\.(div\debmeta|slmcrec|debsess)' | LC_ALL=C sed -n l
1R.slmcrec$
28.11.debsess$
4Ahi.slmcrec$
Cc7.slmcrec$
dc.slmcrec$
h0M.slmcrec$
hWdxlm.slmcrec$
i79W.slmcrec$
ILWm7b.slmcrec$
izebDM.slmcrec$
K7yUk.slmcrec$
kIziXi.slmcrec$
L4XWy.slmcrec$
M.slmcrec$
NR.slmcrec$
Nz7.slmcrec$
o7qXQ.slmcrec$
oD.slmcrec$
pAupd0.slmcrec$
pwxh.slmcrec$
uCptRo.slmcrec$
vWsP9.slmcrec$
YMYtEi.slmcrec$
zV6.slmcrec$
13
  • 2
    -o .......... Commented Nov 29, 2024 at 14:13
  • Ah, if I separate -name clauses with -o (or) it does work! I'm still wondering why the regex doesn't work though. Commented Nov 29, 2024 at 14:16
  • It works for me with find (GNU findutils) 4.10.0 Commented Nov 29, 2024 at 14:18
  • Works with Debian12, find 4.9.0: find /tmp/.debrief -regextype egrep -regex '.*\.(div|debmeta|slmcrec|debsess)'. What is the output of find --version? Commented Nov 29, 2024 at 14:21
  • 2
    Is /tmp/.debrief possibly a symlink? Commented Nov 29, 2024 at 15:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.