Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

An application has a log directory, in which a alot of log output is created. The file structure in this log directory looks something like this:

localhost:/var/log/myapp # ls

appClient22334.a    appClient22336.a    appClient22338.a
appClient22334.b    appClient22336.b    appClient22338.b    
appClient22334.c    appClient22336.c    appClient22338.c
appClient22335.a    appClient22337.a    appClient22339.a
appClient22335.b    appClient22337.b    appClient22339.b
appClient22335.c    appClient22337.c    appClient22339.c

Every day the application generates hundreds of those files, which are all to be stored. The numbers are incrementing.

For most purposes I use logrotate to store and compress log files on a daily base, but in this case I fail to see how this could be done.

The ideal solution would be to have something like


Can anyone of you nudge me into the right direction, if this can be done while using logrotate (maybe a clever way to use prerotate?), or if it is faster/easier to write a specific bash script?

share|improve this question
You say that there are hundreds of files per day. Shall they all be gathered into single per-day logfile? – Netch Mar 28 '12 at 7:46
Yes, thats the plan. – Bjoern Mar 28 '12 at 7:51
up vote 1 down vote accepted

In the interest of keeping things simple, I'd run a daily cron job that concatenates yesterday's log files into one file (e.g. yesterday.log) and on success deletes them, and then run logrotate to (re)name and compress that file. You might be able to coerce logrotate into doing the whole task using sharedscripts but I don't think so and I wouldn't waste time trying to figure it out.

share|improve this answer
Good thinking, I'll follow this approach. – Bjoern Apr 28 '12 at 9:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.