Diagnose performance issues by interrogating system logs, then reclaim disk space safely by truncating oversized log files without deleting them. Validate and adjust log rotation policy by inspecting logrotate configuration and forcing a controlled rotation run.
A user reports the system is running slowly and the root
filesystem is close to full. You suspect a log storm or a
runaway service is filling /var/log. Your job is
to watch logs live, identify a large log file consuming space,
reclaim storage safely, and confirm that logrotate policy is
in place and functioning.
You are fixing the immediate disk pressure without destroying evidence. The goal is “stabilize first, preserve data, then tune rotation.”
journalctl -f.
du.
truncate (preserving
inode and permissions).
/etc/logrotate.conf and
/etc/logrotate.d.
logrotate -f.
journalctl -f
Following the journal gives you immediate evidence of what is spamming errors or creating sustained load. If disk fills due to logs, the journal often shows the root cause at the same time.
-- Logs begin at Tue 2025-07-01 09:00:00, end at Tue 2025-07-18 14:30:00 --
Jul 18 14:25:00 lpic-lab25 kernel: CPU soft lockup detected...
Prefer truncation over deletion. Truncation preserves file ownership, SELinux labels, and open file handles while reclaiming disk space.
du -sh /var/log/syslog && truncate -s 0 /var/log/syslog
du -sh gives a quick “how bad is it” snapshot.
truncate -s 0 drops file contents to zero bytes
without removing the file itself.
5.0G /var/log/syslog
Log file truncated safely.
/etc/logrotate.conf
/etc/logrotate.conf is the entry point for the
rotation policy. It usually defines global defaults and
includes the per-package rules directory.
/etc/logrotate.d
Most services drop their own rotation configuration into
/etc/logrotate.d. This is where you verify that
your noisy service actually has a rotation rule.
logrotate -f /etc/logrotate.conf
Forcing a run is how you validate that your configuration is syntactically correct and that rotations happen as intended without waiting for the daily timer/cron.
logrotate executed manually using config.
journalctl -f
: Follows the systemd journal in real time.
du -sh <path>
: Summarizes disk usage for a file or directory.
truncate -s 0 <file>
: Safely clears a file’s contents without deleting the file.
/etc/logrotate.conf
: Master logrotate configuration.
/etc/logrotate.d
: Per-package/service log rotation rules.
logrotate -f /etc/logrotate.conf
: Forces an immediate logrotate run using the master config.