How to get list of logrotate files

2019-08-20 03:41发布

问题:

How can my program iterate through the log history created by logrotate?

logrotate has many options for file naming. For example, dateext, delaycompress, and rotate all affect the filenames in some way. I want my program to be Linux-friendly and work with most of these options.

I read the entire manpage of logrotate, and did not find any description of how other software can inspect the files that logrotate has produced. Is there perhaps some sister utility that understands what logrotate has done to my logfiles, and can make it easy to retrieve this information?

回答1:

After rereading the manpage 3 more times, I found the following words:

Note that the datestamps generated by this format must be lexically sortable ... when using the rotate option, logrotate sorts all rotated filenames to find out which logfiles are older

So we have a documented method for finding the files. For reverse chronological order, the sorting must be reversed when dateext is used, of course.



标签: logrotate