如何在 Linux 命令行的 find 命令中使用 -regex

How to use -regex in the find command on Linux command line

objective 是查找并列出带有 "messages" and/or "error.log" 等的任何内容。在开头然后列出 "messages.1..99" 和 "error.log.1..99" 使用正则表达式。

此命令适用于但是,它需要我进行多次 -or 搜索,但为简化起见,我希望在搜索中的一组中有多个。比如:

# find /var/log -maxdepth 1 -type f -size +1M -name [messages|error.log|secure.log|kern.log...]?[0-9]|[0-9][0-9] ! -iname "*.gz"

没有

# find /var/log -maxdepth 1 -type f -size +1M -name "messages?[0-9]" -o -name "messages?[0-9][0-9]"

如何使用正则表达式执行此命令?

# find /var/log -maxdepth 1 -type f -size +1M -name "[messages,error.log,kern,secure]?[0-9]" ! -iname "*.gz"

我对正则表达式的尝试没有在标准输出中打印任何内容:

# find /var/log -maxdepth 1 -type f -size +1M -regex -name "[messages,error,kern,secure]?[0-9]" ! -iname "*.gz"

试试这个:

find /var/log -maxdepth 1 -type f -size +1M -type f -regextype egrep -regex '.*(messages|error|kern|secure)\.[0-9]+.*' -not -name \*gz