I’ve got a short script to move apache log files that are older than x days to a storage location. The regex is capturing the jk.shm.some_number file name in the mod_jk directory, which is an undesired behavior (not a huge issue as I use the mtime flag with a few days cushion to avoid accidental hosing of current active files. Probably the reason I haven’t seen this issue pop up so far). The whole regex is:'[error,access,error_log,access_log,mod_jk.log]*.[0-9]*' Which I think has only been working due to dumb luck. I’ve also tried isolating the mod_jk part to run by itself 'mod_jk.log.[0-9]*' and it works as expected (with or without the \ in front of the .). As soon as i include it inside the brackets, it picks up the jk.shm.some_number file – I’m guessing because it matches a character range in the brackets. I’m trying to work this out using RegexBuddy, but I thought one of the smart folks out there might be able to point out my mistakes and help get me on the right path.
This is the current line that ‘works’ with the -mtime flag removed:
find -name '[error,access,error_log,access_log,mod_jk.log]*.[0-9]*' -type f
If your
findhas the-regexoption, you can use that; otherwise, you will have to split this into individual glob patterns.Note that in glob patterns,
*is just a DOS-style wildcard, not a regex repetition operator. If you havefind -regex, you have more control over matching.In both regex and glob
[ab|cd]only matches one character out of the set enumerated inside the brackets; the pipe character just represents itself in this context.