I use run my programm under gnu-screen with enabled logging to a file (log on / logfile options in .screenrc). But after some time the log file became too big.

Is there some way to limit size of a log file?


Unless you want real-time control over the size of the log, you can use logrotate with cron to accomplish this.

Assuming you want to rotate screenlog.log in your /home/username/ directory, you would create something like this configuration file:


/home/username/screenlog.log {
  size 100k

then either run logrotate /home/username/screenlog-rotate.conf or set it up as a cron job to be run periodically. Keep in mind logrotate needs to be run as root by default and the configuration file (screenlog-rotate.conf above) needs to also be chowned to root, otherwise it will complain the permissions on the configuration are wrong. Test by running logrotate with the -v flag to see if it understood what you meant.

The above configuration file is simple and will not keep old log files. It will just remove the file if it's over the size given, while screen still outputs its log as usual (I tested this). If you want the old logs to be kept, then you need to add rotate N where N is how many rotated logs you want to keep.

Check out man 8 logrotate for details on how to configure logrotate. Here's a related question: How to limit log file size using >>

logrotate seems to be included by default in Arch Linux, but I'm not sure of other distributions. I'd expect at least Debian to have it installed by default and it should be easy to install using a package manager.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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