You use your regex as a flag parameter for
find, so there should be no problem there, even though
sudoers does not support regular expressions, only shell wildcard-like globbing (see man page). So what you are trying seems conceptually sound.
At least for GNU bash 4.x and later the -regex default patterns' syntax is the EMACS regex syntax. There may be subtle differences (which I'd have to research to know) with, say, things you might be better acquainted with, such as
grep utilities regex' syntaxes...
If you are on RHEL, check your doc carefully on that, as things may be slightly different...
In any case you can always specify, for instance:
operator ALL=NOPASSWD: /usr/bin/find -type f -regextype grep -regex ".*core\.[0-9]*$"
... means any regular file from the current directory down, which starts with one or more of any characters, followed by the string "core.", ending with one or more digits.
Again, is that what you want ?
If not, state in plain English what you want your regex to do, or just give a few significant examples of what you want to catch, so I may translate that to a proper GNU flavored grep-style regex.
A word of caution:
- To use the same
sudoers rule on various platforms I would recommend you systematically specify the type of regex syntax you mean to apply, as shown above.
- In the context of
sudoers, I would always specify the path down which you want to execute your search. Use the
-path flag followed by the absolute path of top most level of the sub-tree you want to search.
All said, for readability and safety reasons when dealing with
sudoers, I generally recommend writing a minimal wrapper script for your
find cmd, e.g. called
findcore.sh, owned by
root:root, with permissions 751, which accepts no parameters (via the use of
operator ALL=NOPASSWD: /path/to/findcore.sh ""
You can then easily update the content of the script via SVN or another mechanism without
sudo password, by including a second rule in your
sudoers file, specifically for updates performed via your favorite mechanism.