Find files not matching multiple patterns and then delete anything older than 10 days

Hi,
I have multiple files in my log folder. e.g:

a_m1.log
b_1.log
c_1.log
d_1.log
b_2.log
c_2.log
d_2.log
e_m1.log
a_m2.log
e_m2.log

I need to keep latest 10 instances of each file.
I can write multiple find commands but looking if it is possible in one line.
m file are monthly and other files are daily.

Thanks

Your requirements are not at all clear.

  1. What constitutes a file?
  2. How are instances of a file determined?
  3. How are the latest instances of a file determined? (By name? By timestamp? Something else?)
  4. Are you trying to keep 10 monthly instances and 10 daily instances of a file? Or 10 instances of daily and monthly files? Or, maybe, 9 daily instances and 1 monthly instance???
1 Like

Hi,
1)Everything ending with *.log is a file
2) a_m?.log is an instance of "a" monthly file, similarly e_m?.log is instance of "e" monthly file b_?.log is instance of "b" daily file and so on..
3) Latest instance is determined by timestamp of file
4) Im keeping 10 latest of every type of file. 10 latest instances based on timestamp of a_m?.log, b_?.log,c_?.log and so on

...not what you asked for, but maybe enough:

rm *_1[1-9].log *_m1[1-9].log *_[2-9][0-9].log *_m[2-9][0-9].log

...delete *_11.log - *_99.log and *_m11.log - *_m99.log...

I'm afraid the echo to your request is and will stay sparse, unless you supply way more detail. Inferring from what we've got now, I'd say that a_m?.log can be expanded to a_m0.log to a_m9.log , and that's it. There you've got your ten files, regardless of their age. Of course there are many ways to interpret what you've given, but (at least for me) that's not our task.

How about posting a serious specification without leeway for interpretation, showing a directory listing with at least a representative number of files, and e.g. one or two of your "multiple find commands"?