Recently, I have setup a script that outputs to a single log file... After quite a while this file begins to become too large to manage. I was wondering what the easiest way is to setup log rotations for every few hundred lines located in the original log file?
Asked
Active
Viewed 2,805 times
1
-
@muru ?? Are you marking all my posts as duplicates because every one you marked so far is not even remotely a duplicate? – NerdOfCode Jan 06 '18 at 07:17
-
1stop exaggerating. I haven't marked all your posts as duplicates and those that I have are pretty much duplicates. – muru Jan 06 '18 at 07:18
1 Answers
2
You can use logrotate
, execute this command to install it:
sudo apt-get install logrotate
Logrotate's configuration can generally be found in 2 places on Ubuntu (from Digital Ocean):
/etc/logrotate.conf
: this file contains some default settings and sets up rotation for a few logs that are not owned by any system packages. It also uses an include statement to pull in configuration from any file in the/etc/logrotate.d
directory./etc/logrotate.d/
: this is where any packages you install that need help with log rotation will place their Logrotate configuration.
On a standard install you should already have files here for basic system tools like apt
, dpkg
, rsyslog
and so on.
By default, logrotate.conf
will configure weekly log rotations (weekly
), with log files owned by the root user and the syslog group (su root syslog
), with four log files being kept (rotate 4
), and new empty log files being created after the current one is rotated (create
).
If you want to learn more about how to use this tool, please visit the following link: How To Manage Logfiles with Logrotate on Ubuntu 16.04
Hope this helps.

galoget
- 2,963
-
-
You can test it by doing a dry run with
sudo logrotate /etc/logrotate.conf --debug
– Ricardo Nov 19 '20 at 18:32