Linux Disk Space Log Files: Find & Free Space
In this article
Linux disk space log files can quietly consume gigabytes, and the fastest way to reclaim space is to locate the largest logs, check their rotation settings, and truncate or delete the ones you no longer need. This article explains where logs accumulate, how to measure their impact, and how to safely manage them without breaking system monitoring.
Why Log Files Grow Unchecked
Most Linux distributions use a logging daemon (like rsyslog or journald) that writes messages from the kernel, services, and applications to files under /var/log. These files are meant to be rotated—old entries are compressed or deleted—but rotation is often misconfigured or disabled. A single application that logs verbose debug output, a misbehaving service that writes errors every second, or a cron job that runs a noisy script can fill a disk within days. On a default Ubuntu or Debian system, /var/log typically holds 100–500 MB, but on busy servers it can easily grow to tens of gigabytes.
How to Check Which Logs Are Eating Space
The first step is to see the biggest files in /var/log. Use the du command to sort directories by size:
sudo du -ah /var/log | sort -rh | head -20This lists files and directories with sizes, largest first. For a more human-friendly view, add -h to du (already included above). You can also use ncdu (install it with your package manager) for an interactive, navigable interface. If you use systemd-based logging, journalctl --disk-usage shows how much space the journal occupies.
Understanding Log Rotation
Log rotation is handled by logrotate, a utility that renames, compresses, and eventually deletes old logs according to rules in /etc/logrotate.conf and files in /etc/logrotate.d/. A typical rule looks like:
/var/log/example.log {
weekly
rotate 4
compress
missingok
notifempty
}This rotates the log weekly, keeps four old copies, and compresses them. If a service writes to a log file that is not listed in any logrotate rule, that file will never be rotated and will grow until the disk is full. You can check if a file is covered by running logrotate --debug /etc/logrotate.conf (it shows what would happen without actually doing it).
Safe Ways to Free Up Space
Before deleting anything, make sure you don't need the logs for troubleshooting or compliance. Here are safe methods, from least to most aggressive:
- Truncate a file instead of deleting it. Deleting a log file that a process has open can cause the process to keep writing to the unlinked inode, wasting space until the process restarts. Truncating with
sudo truncate -s 0 /var/log/example.logclears the contents while keeping the file open. - Use logrotate manually to force rotation:
sudo logrotate -f /etc/logrotate.conf. This applies all rules immediately, compressing and removing old logs as configured. - Clean the journal if you use systemd:
sudo journalctl --vacuum-size=200Mreduces the journal to 200 MB, and--vacuum-time=7dremoves entries older than 7 days. - Remove old compressed logs like
*.gzor*.1if you are sure you don't need them. Usesudo find /var/log -name "*.gz" -deletewith caution.
Preventing Future Disk Full Issues
To stop logs from filling the disk again, take these steps:
- Review
/etc/logrotate.d/and add rules for any application that writes its own logs (e.g., Nginx, Apache, Docker). - Increase rotation frequency for high-volume logs (change
weeklytodaily). - Set a maximum size for the journal in
/etc/systemd/journald.confby uncommentingSystemMaxUse=and setting a value like500M. - Use
logrotate'ssizedirective to rotate based on file size rather than time:size 100M.
Common Misconceptions
One common mistake is assuming that deleting a log file frees space immediately. If a process still has the file open, the space is not released until the process closes it. That's why truncation is safer. Another misconception is that /var/log is the only place logs are stored. Some applications (like Docker, Kubernetes, or user-level apps) write to other directories, such as /var/lib/docker/containers or ~/.local/share/. Always scan the entire disk with du -xh / | sort -rh | head to find large directories beyond /var/log.
Comparing Logging Systems: rsyslog vs. journald
Traditional Linux systems use rsyslog, which writes plain-text files that are easy to read and rotate. Newer distributions use journald, which stores logs in a binary format with metadata, making them harder to read without journalctl. Journald can be configured to forward logs to rsyslog for traditional file-based logging. The choice affects disk usage: journald by default limits its size to 10% of the filesystem, but this can be large on big disks. If you prefer plain-text logs, you can disable persistent journal storage and rely on rsyslog.
Frequently Asked Questions
How do I find the largest log files on my Linux system?
Run sudo du -ah /var/log | sort -rh | head -20 to list the biggest files in /var/log. For a system-wide scan, use sudo du -xh / | sort -rh | head -20 (the -x flag stays on one filesystem).
Is it safe to delete log files?
Generally yes, but you may lose useful troubleshooting data. Prefer truncating with truncate -s 0 over deleting, especially if the file is in use. For logs that are rotated, deleting old compressed files is usually safe.
Why does my disk fill up even after I delete logs?
If a process keeps the deleted file open, the space isn't freed. Restart the service or use truncate. Also check other locations like /var/lib/docker, /tmp, or user caches.
How do I change log rotation frequency?
Edit the relevant file in /etc/logrotate.d/ or /etc/logrotate.conf. Change weekly to daily or add size 100M to rotate based on size. Then test with sudo logrotate --debug /etc/logrotate.conf.
What is the difference between truncating and deleting a log file?
Truncating sets the file size to zero but keeps the inode and any open file descriptors valid. Deleting removes the directory entry; if a process has the file open, it continues writing to the unlinked inode, and the space is only freed after the process closes it.