Rotate or delete an overgrown syslog file (safely)

If your /var/log/syslog (Debian/Ubuntu) or /var/log/messages (RHEL/CentOS/Alma/Rocky) has ballooned to multiple gigabytes, you’re usually seeing one of two things: a service spamming logs, or log rotation not running. The good news is you can reclaim space safely without breaking logging — as long as you avoid the classic trap of deleting a file that a daemon still has open. In this guide, we’ll walk through the safest options: rotating with logrotate, truncating in place, recovering space after an accidental rm, and (if needed) vacuuming systemd’s journal.

Table of Contents

If your /var/log/syslog (Debian/Ubuntu) or /var/log/messages (RHEL/CentOS/Alma/Rocky) has ballooned to multiple gigabytes, you’re usually seeing one of two things:

  1. A misbehaving service spamming logs, and/or
  2. Log rotation not running (or not configured).

The good news: you can reclaim space safely without breaking logging — as long as you avoid the classic trap of deleting a file that a daemon still has open.


Quick orientation: what’s writing the file?

On many distributions, the file is written by rsyslog (or sometimes syslog-ng). On more modern systems, systemd-journald may be the primary store, with syslog acting as a forwarder.

Common log files:

  • Debian/Ubuntu: /var/log/syslog, /var/log/auth.log, /var/log/kern.log
  • RHEL-like: /var/log/messages, /var/log/secure

Option A (recommended): rotate it with logrotate

Most systems already use logrotate. Rotation renames the current log, starts a fresh one, and optionally compresses and prunes old logs.

1) See whether logrotate manages syslog/messages

Typical config files:

  • Debian/Ubuntu: /etc/logrotate.d/rsyslog
  • RHEL-like: /etc/logrotate.d/syslog or /etc/logrotate.d/rsyslog

2) Force a rotation right now

  • -v shows what it’s doing
  • -f forces rotation even if it’s “not time yet”

3) A solid baseline rotation rule (example)

If you need to tune your syslog rotation, a common pattern is:

Notes:

  • rotate 14 keeps two weeks of history (adjust to taste)
  • compress + delaycompress keeps last rotated file uncompressed for easy reading
  • copytruncate is useful when the writer doesn’t reliably close/reopen logs — it copies the file then truncates the original without needing the daemon to reopen.

Many default distro configs use a postrotate block to signal rsyslog instead. Either approach can work; the default config shipped by your distro is usually a good starting point.


Option B (fastest): truncate the log to zero (safe “delete”)

If the log is huge and you just need space now, truncating is often the safest immediate action.

Truncate syslog/messages without stopping logging

Alternative (equivalent):

Truncation keeps the same inode and file permissions — the logging daemon can keep writing without getting confused.


Avoid the trap: rm doesn’t always reclaim space

If you do this:

…rsyslog may continue writing to the already-open file handle. The directory entry is gone, but disk space may not be freed until the daemon closes the file.

If you deleted it and disk space didn’t come back

Find deleted-but-still-open log files:

Then restart the logging service:

After restart, the space tied to those deleted file handles is released.


If you’re using systemd journal: prune it too

On many modern distros, journald can be the real disk hog.

Check journal usage:

Prune old entries by time:

Or cap by size:

If journald is persistently enormous, review /etc/systemd/journald.conf (e.g., SystemMaxUse=) — but change limits thoughtfully, especially on incident-prone systems.


Why did it get huge? Find the spammer

Rotation prevents infinite growth, but it’s still worth identifying what is flooding logs.

Quick peek at the latest messages

Find frequent talkers (rough heuristic)

Syslog formats vary, but a fast-and-loose way to spot patterns:

If the output looks weird, don’t worry — paste a handful of representative log lines and you can craft a better parser for your specific format.

Common culprits

  • A service in a crash/restart loop
  • DNS failures or timeouts (lots of retries)
  • Disk full / permission errors causing repeated writes
  • Misconfigured application log level (debug in production)

A practical playbook

When you log in and see a 30 GB syslog:

  1. Truncate (fast reclaim): truncate -s 0 /var/log/syslog
  2. Force rotate: logrotate -vf /etc/logrotate.conf
  3. Verify rotation schedule (cron/systemd timer) is actually running
  4. Find the spammer and fix the root cause
  5. Set retention to match your needs (compliance, troubleshooting, disk size)

Conclusion

The safest way to “delete” an overgrown syslog file is usually to rotate it (logrotate) or truncate it (keep the file but clear contents). Avoid rm unless you understand open file handles — and don’t forget that journald may be the real source of disk usage.

If you want, share:

  • your distro (Ubuntu vs RHEL-like),
  • whether you use rsyslog/syslog-ng, and
  • the output of journalctl --disk-usage

…and you can tailor rotation and retention settings to your environment.

Have a project or a problem?

Talk with a senior engineer for practical recommendations—no obligation.

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.