-1

I want to use regex to find all coredump files under a directory. The pattern of the file name is core.1234

find /public_html -type f -regextype sed -regex "core.{[0-9]+:[0-9]+}"

Please advice.

Tester
  • 177
  • 1
  • 1
  • 7

3 Answers3

3

You missed some info on how -regex works

-regex pattern
File name matches regular expression pattern. This is a match on the whole path, not a search. For example, to match a file named ./fubar3', you can use the regular expression.*bar.' or .*b.*3', but notf.*r3'. The regular expressions understood by find are by default Emacs Regular Expressions, but this can be changed with the -regextype option

In particular the regex needs to match the whole path. You don't need to change the regex type or even supply a -regex

find /public_html  -name "core.[0-9][0-9][0-9][0-9]"

does the trick and will find core files at any level below /public_html.

user9517
  • 115,471
  • 20
  • 215
  • 297
0

/public_html is part of the path, so try find /public_html -type f -regextype sed -regex ".*/core.{[0-9]+:[0-9]+}"

egg
  • 31
  • 2
0
find /public_html -type f -regextype sed -regex "/public_html/core.[0-9]\+"

EDIT: Added example

$ ls public_html/
core.asdd  core.1asd  core.123  core.1234  core.12362  core.1456 core.8452

$ find /public_html -type f -regextype sed -regex "/public_html/core.[0-9]\+"
/public_html/core.123
/public_html/core.1234
/public_html/core.1456
/public_html/core.12362
/public_html/core.8452
Quantim
  • 1,358
  • 10
  • 15
  • Can you explain how this solves the problem? – chicks Mar 14 '17 at 16:09
  • u can use regexp as is requested in question. This syntac accept one or more numbers after dot in case of part after dot is process number, which can have different number of digits. Also solve problem with directory name in regex formula Example in aswer – Quantim Mar 14 '17 at 20:31