[Insights](/insights/) / [Engineering Playbooks](/insights/engineering_playbooks/)

# The fastest way to clean up disk space on server

Fastest safe commands to clean up disk without loosing your data

![Ivan Borshchov](https://static.devforth.io/adminusers/avatars/2026/48db9847-d461-40cd-b344-f2bd7b0d98ca-avatar_ivan@devforth.io_f4ce9df9-8363-4314-9345-28753c76a386.jpeg)

Ivan Borshchov

CEO & System Architect @ Devforth

Apr 12, 2021

![The fastest way to clean up disk space on server](https://static.devforth.io/posts/logo-svg/2026/6d1ac232-02d3-487b-8be5-77629c04750f-logo-preview-new.svg)

![The fastest way to clean up disk space on server](https://static.devforth.io/posts/logo-svg/2026/6d1ac232-02d3-487b-8be5-77629c04750f-logo-preview-new.svg)

Your production crashed because "no space left on device" and you have no guess what to delete fast? Do not worry! Here I will show you largest useless points of data and how to find and kill them.

> ☝ Save the post for future, it happens!

Install `ncdu` to check who uses space:

```bash
apt install ncdu
```

> 🤔 Yes, you will need ~100kB of free space to install `ncdu`: just find some trash in your home directory

Run it:

```bash
ncdu /
```

I suggest you not spend time now, and enter `/var/log` folder instantly:

![Use ncdu to find largest folders and files](https://static.devforth.io/posts/images/2026/b5ee6de2-3c48-45ba-a948-a65d4377e23d-image_1775045072539.png)

Use ncdu to find largest folders and files

In most cases it is systemd's `journal` folder and `btmp` file.

Trim current large journal immediately:

```bash
journalctl --vacuum-size=50M
```

> 😣 So, after several months of work our CI server had `3.6 GB` of useless for us data created by OS default tools. Now it is empty.

Also let's force to trim it automatically when journal will exceed `50 M`. To limit max used space for journal, open a config file:

```bash
 nano /etc/systemd/journald.conf
```

And add `SystemMaxUse` under `[Journal]` section:

```bash
[Journal]
SystemMaxUse=50M
```

> 🛌 Sleep better after doing it

## [](#fix-largebtmpfile-invarlog)Fix large `btmp` file in `/var/log/`

This file most time contains logs of unsuccessful brute-force attempts. To remove file content on one time basis:

```bash
echo '' > /var/log/btmp
```

To fix it in future:

-   add same command under daily CRON
-   Configure `fail2ban` or alternative to fix root cause of the issue and ban brute forcers earlier

## [](#are-you-using-docker)Are you using docker?

One of the largest points of useless data.

Remove most of useless docker data:

```bash
docker system prune -f
```

Also you might want to remove unused images:

```bash
docker rmi $(docker images -f "dangling=true" -q)
```

[

Back to insights

](/insights)

[](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdevforth.io%2Finsights%2Fthe-fastest-way-to-clean-up-disk-space-on-server)[](https://bsky.app/intent/compose?text=The%20fastest%20way%20to%20clean%20up%20disk%20space%20on%20server%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fthe-fastest-way-to-clean-up-disk-space-on-server)[](https://x.com/intent/tweet?text=The%20fastest%20way%20to%20clean%20up%20disk%20space%20on%20server%20by%20%40ivanborshchov%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fthe-fastest-way-to-clean-up-disk-space-on-server)

[

Summarize with AI

](/lab/chat/?prompt=Extract%20main%20points%20from%20post%3A%20https%3A%2F%2Fdevforth.io%2Finsights%2Fthe-fastest-way-to-clean-up-disk-space-on-server)

Table of Contents

-   [Fix large btmp file in /var/log/](#fix-largebtmpfile-invarlog)
-   [Are you using docker?](#are-you-using-docker)

[](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdevforth.io%2Finsights%2Fthe-fastest-way-to-clean-up-disk-space-on-server)[](https://bsky.app/intent/compose?text=The%20fastest%20way%20to%20clean%20up%20disk%20space%20on%20server%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fthe-fastest-way-to-clean-up-disk-space-on-server)[](https://x.com/intent/tweet?text=The%20fastest%20way%20to%20clean%20up%20disk%20space%20on%20server%20by%20%40ivanborshchov%0A%0Ahttps%3A%2F%2Fdevforth.io%2Finsights%2Fthe-fastest-way-to-clean-up-disk-space-on-server)
