2

The objective is to find and list anything with "messages" and/or "error.log" etc.. in the beginning then list both "messages.1..99" and "error.log.1..99" using regular expressions.

This command works for however, it would require me to make many -or searches, but to simplify, I would like to have multiple in a set within the search. Like for instance:

# 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"

not

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

How might I perform this command with regular expressions?

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

My attempt with regex doesn't print anything in standard out:

# find /var/log -maxdepth 1 -type f -size +1M -regex -name "[messages,error,kern,secure]?[0-9]" ! -iname "*.gz"
3
  • 1
    That (the not finding anything) will be for two reasons: a) [messages,error,kern,secure] is a weird character class and not what you think it is and b) there's nothing to match the actually found ./ at the beginning of the file names ... and you can't use -regex -name like that, either Commented Aug 18, 2019 at 20:46
  • regex matches everything, the whole path, you need to match /var/log/ too. Commented Aug 18, 2019 at 21:02
  • As your complex query does not work, reduce the complexity! For example, try -name messages instead of -name "[messages,error,kern,secure]?[0-9]". Then you might get the suspicion that you should look up how to use -regex. Commented Aug 18, 2019 at 21:08

1 Answer 1

4

Try this:

find /var/log -maxdepth 1 -type f -size +1M -type f -regextype egrep -regex '.*(messages|error|kern|secure)\.[0-9]+.*' -not -name \*gz
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.