Skip to content

Full disk on Linux server: how to free up space

Medium 20 min Updated:

Quick answer

When the disk is full, first check usage with `df -h` and find large files and folders with `du`. Then clean unnecessary logs, package cache and temporary files, but be careful not to delete active logs without rotation. Finally, configure logrotate and remove old archives to prevent the disk from filling up again.

How to recognize the problem

  • Services cannot write data to the database or files
  • Application reports error "No space left on device"
  • You cannot log in to the server via SSH
  • Website returns error 500 or does not load
  • System logs stop being written

Most common causes

Uncontrolled logs

Application or system log files grow without rotation and can take up all free space.

Package cache and updates

Downloaded packages and package manager cache (APT, DNF) accumulate over time.

Temporary files and sessions

Files in `/tmp` and user sessions can remain forever if not cleaned.

Large database files

Backup files, database dumps or archives can be large and forgotten.

Incorrectly mounted disks

If a partition is not mounted properly, data is written to the root partition and fills it up.

Step-by-step fix

  1. 1

    Check disk usage

    Run df -h to see which partition is full. Pay attention to the Use% column and the partition that is 100% full. If the root partition (/) is full, continue by checking large folders.

  2. 2

    Find the largest folders

    As root, use du -h --max-depth=1 / to see usage by directory. Then enter the largest folder and repeat the command. This way you will quickly locate where space is being used.

  3. 3

    Find large files

    Run as root find / -type f -size +100M -exec ls -lh {} \; to find files larger than 100 MB. Delete or move those that are not needed, but first check what they are for and make a backup if the data is important.

  4. 4

    Clean logs

    Logs are usually located in /var/log. Before cleaning, make a backup of logs if you need them for diagnostics. You can delete old archived logs (*.gz, *.1) or truncate them as root with the command truncate -s 0 /var/log/name.log. Do not delete active logs, but truncate or rotate them.

  5. 5

    Clean package cache

    On Debian/Ubuntu systems, run as root or with sudo: apt clean and apt autoremove. On RHEL/CentOS/Fedora systems, use as root or with sudo: dnf clean all and dnf autoremove. This will free up space taken by downloaded packages.

  6. 6

    Clean temporary files

    Review /tmp and /var/tmp and delete files older than a few days. Be careful with files currently used by active processes.

  7. 7

    Configure logrotate

    Check the configuration in /etc/logrotate.conf and /etc/logrotate.d/. Make sure logs are rotated and older versions are deleted. You can add rotate 7 and daily for key logs.

  8. 8

    Check disk mounts

    Run mount and df -h to see if all partitions are properly mounted. If a partition is not mounted, data is written to the root partition and can fill it up.

If nothing helps

If you still do not have enough space, check if there are deleted files held by active processes. The command lsof +L1, run as root, shows such files; safely restart the process holding them. Consider adding a new disk or extending the partition. For databases and applications with large data, regularly back up and clean old dumps. Finally, if the disk is physically small, plan migration to a larger disk or cloud storage.

How to prevent it

  • Regularly check disk usage with `df -h` and `du`
  • Configure logrotate for all applications that write logs
  • Clean package cache and temporary files monthly
  • Use monitoring tools that will alert you when disk reaches 80%

When to call a professional

If you cannot access the server or do not know which files are safe to delete, contact IT support. Also, if the disk is physically faulty or there is suspicion of hardware failure, it is better to have an expert examine it.

IT infrastructure maintenance · Servers, networks, backup, security and helpdesk

FAQ

How to quickly free up space on the root partition?

First check `df -h` to see how much space is left. Then find large files and folders using `du` and `find`, and delete unnecessary logs and cache. If urgent, you can temporarily delete old log archives, but make a backup first if you need them.

Can I freely delete files in /tmp?

You can delete files older than a few days, but first check that they are not used by an active process. It is best to use `tmpwatch` or `systemd-tmpfiles` with an appropriate timer that automatically cleans `/tmp`.

Why does my disk fill up again after cleaning?

The most common cause is lack of log rotation or an application that creates large temporary files. Check logrotate configuration and set limits for applications that write a lot of data.

Share
Didn't find a fix?The AI IT assistant is available 24/7. Describe the problem or send a screenshot of the error and get instructions for your case.Ask the AI IT assistant