How to Free Up Disk Space on a Full Linux System

Harendra BarotHarendra Barot
2 min read

Table of contents

  1. Check Disk Usage
    ~ Run the following command to identify which partitions are full:

     df -h
    

    ~ Look for the partition with 100% usage, usually /.

  2. Clear Temporary Files
    ~ Free up space by clearing temporary files:

     sudo rm -rf /var/tmp/*
     sudo rm -rf /tmp/*
    
  3. Remove Unused Package Files
    ~ Clear cached .deb files stored by apt:

     sudo apt-get clean
    
  4. Locate Large Files
    ~ Identify large files in your filesystem:

     sudo du -ah / | sort -rh | head -n 20
    

    ~ Delete unnecessary large files or move them to another storage location.

  5. Check Log Files
    ~ Logs can often grow excessively large. Truncate or delete old logs:

     sudo journalctl --vacuum-size=50M
     sudo rm -rf /var/log/*.gz /var/log/*.1
     sudo truncate -s 0 /var/log/syslog
     sudo truncate -s 0 /var/log/auth.log
    
  6. Uninstall Unused Applications
    ~ Remove unnecessary applications to reclaim space:

     sudo apt-get remove --purge <package_name>
     sudo apt-get autoremove
    
  7. Retry the Update/Installation
    ~ After clearing space, reattempt the operation:

     sudo dpkg --configure -a
     sudo apt-get install -f
    

Long-Term Prevention

  • Monitor Disk Space: Regularly check disk usage with df -h and du.

  • Set Log Rotation: Use tools like logrotate to manage log sizes.

  • Partition Optimization: Allocate adequate space to /var or use separate partitions for logs and temporary files.

By following these steps, you should be able to resolve the error and free up space for system operations.

1
Subscribe to my newsletter

Read articles from Harendra Barot directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Harendra Barot
Harendra Barot

I'm an IT professional and business analyst, sharing my day-to-day troubleshooting challenges to help others gain practical experience while exploring the latest technology trends and DevOps practices. My goal is to create a space for exchanging ideas, discussing solutions, and staying updated with evolving tech practices.