IO Redirection – How to Limit Log File Size Using >>

io-redirectionlimitsize;

How can I limit the size of a log file written with >> to 200MB?

$ run_program >> myprogram.log

Best Answer

If your application (ie. run_program) does not support limiting the size of the log file, then you can check the file size periodically in a loop with an external application or script.

You can also use logrotate(8) to rotate your logs, it has size parameter which you can use for your purpose:

With this, the log file is rotated when the specified size is reached. Size may be specified in bytes (default), kilobytes (sizek), or megabytes (sizem).

Related Question