Marcio Cunha

Disk space full? How to clean caches and logs in Linux

Learn how to recover storage space on development partitions cluttered by old packages and logs. Discover safe commands to clean up Linux.

Marcio Cunha•4 min
Also available in:PortuguêsEspañol
Summary
  • Accumulated log files and package caches silently consume gigabytes in development workstations.
  • The package manager stores old installation files that can be safely removed to free up immediate space.
  • Systemd accumulates event history in journal files that easily exceed gigabytes if not limited.
  • Automated maintenance routines prevent unpleasant surprises with full partitions during long builds.
  • Adjusting retention policies ensures a clean environment without compromising operating system stability.

Why Linux accumulates clutter in development partitions

Working with programming on Linux means running constant builds, downloading heavy dependencies, and accumulating invisible traces. Over time, the root directory or the partition dedicated to the operating system starts issuing disk full alerts. This happens because tools like package managers and web servers save backup copies and detailed logs of every operation without clearing the past. Before trying drastic solutions, such as reinstalling the system or resizing partitions, it is worth understanding where this volume of data hides.

In practice, this means that a large portion of the occupied space belongs to temporary files that have already served their purpose. While you write code, the system records debugging logs to help track errors. If these files grow unchecked, they choke the disk and can even slow down the environment, a problem similar to what we discuss in our article on how to spot IOPS bottlenecks and latency on Linux. The secret to keeping the machine healthy is to adopt a periodic routine of preventive cleaning.

How to clean the package manager cache safely

One of the most common sources of wasted space in Debian and Ubuntu-based distributions is the APT cache, the system responsible for downloading and installing programs. Every time you update the system, compressed installation files are saved in a hidden folder on the disk to allow quick reinstallation if needed. However, in development routines, these old packages rarely become useful again and only serve to occupy precious gigabytes.

To check how much space APT is storing and perform safe cleanup, run the following commands in the terminal:

sudo apt-get clean
sudo apt-get autoclean
sudo apt-get autoremove --purge

The clean command completely wipes out the local repository of downloaded packages, while autoclean removes only old versions that have already been replaced by recent updates. Meanwhile, autoremove eliminates orphaned libraries and dependencies that were automatically installed by other programs but no longer serve any purpose. This trio of commands instantly breathes new life into your storage, optimizing the environment much like the performance boost gained by optimizing builds, as explained in how to speed up builds and containers on the Linux kernel.

How to control the excessive growth of systemd logs

The Linux initialization and service management system, known as systemd, maintains a centralized record of everything happening in the operating system. These records, called journal logs, are extremely useful for troubleshooting hardware failures or software execution errors. The problem is that, by default, they can grow indefinitely until they occupy all the free space on the root partition.

To find out how much space the logs are currently consuming, you can check the disk usage of the logging directory using the built-in audit command:

journalctl --disk-usage

If the result shows an alarming value, you can manually prune this history to free up space instantly. The following command reduces log files to keep only the volume generated over recent days:

sudo journalctl --vacuum-time=7d

If you prefer to limit the total size instead of time, you can set a strict cap, such as limiting total storage to five hundred megabytes using the parameter --vacuum-size=500M. This practice prevents event history from choking your workspace and ensures long-term stability.

How to clean browser caches and development environments

In addition to operating system files, developers accumulate a massive amount of temporary data in user directories. Tools like Docker, npm, pip, and Gradle create robust local caches to speed up future downloads. While this improves build speed, the accumulated volume can easily exceed tens of gigabytes in just a few months of intense use.

To reclaim this space without corrupting your running projects, use specific commands for each development ecosystem:

  1. Remove stopped containers, orphaned images, and unused volumes by Docker with the deep cleanup command: docker system prune -a --volumes
  2. Clean the global package manager cache of Node.js by running: npm cache clean --force
  3. Delete temporary Python compilation files by clearing the pip cache directory with: pip cache purge

These simple actions return valuable space to the disk and prevent sudden freezes during heavy tasks. Maintaining the habit of running these cleanups avoids the stress of dealing with full partitions during critical code delivery moments.

Conclusion and preventive maintenance routine

Managing disk space on Linux does not have to be a reactive task performed only when the system displays full storage errors. By incorporating small cleanup routines to remove old APT caches, prune systemd journals, and purge obsolete container images, you ensure a development environment that remains agile and predictable. Adopting these best practices turns system maintenance into a simple habit, allowing you to focus all your energy on creating quality code without worrying about hardware bottlenecks.