If your Linux machine’s disk is full, you might be wondering which files or directories are consuming the most space.
Here is a guide that will help you, in case you have some space left you can use ncdu
or otherwise just use find
.
NCDU #
If there is some space left on your Linux, I highly recommend using ncdu
, here is what the man page
has to say:
ncdu (NCurses Disk Usage) is an interactive curses-based version of the well-known du(1), and provides a fast way to see what directories are using your disk space.
Install NCDU #
To install ncdu
on a Debian-based system (like Ubuntu), use the following command:
apt update && apt install ncdu
Replace apt
with your distribution’s package manager (e.g., yum
, dnf
, pacman
) if you’re using a different Linux distribution.
Use NCDU #
When you start ncdu
, it scans the disk from the current working directory and provides an interactive view of disk usage. To use it, navigate to the directory you want to scan (e.g., /) and run:
ncdu
It will open up the tool and start scanning:
┌───Scanning...───────────────────────────────────────────┐
│ │
│ Total items: 330084 size: 1.8 GiB │
│ Current item: /proc/2631873/task/2633196/fdinfo/0 │
│ │
│ Warning: error scanning /proc/263187...33132/fdinfo/287 │
│ some directory sizes may not be correct │
│ │
│ . Press q to abort │
└─────────────────────────────────────────────────────────┘
After the scan is complete, you will see a screen that allows you to navigate the file system with the arrow keys. Files and directories are sorted by size, in descending order:
ncdu 1.15.1 ~ Use the arrow keys to navigate, press ? for help
--- / ----------------------------------------------------------
26.0 GiB [##########] /var
1.7 GiB [ ] /usr
771.0 MiB [ ] /root
112.5 MiB [ ] /boot
6.3 MiB [ ] /opt
5.2 MiB [ ] /etc
1.5 MiB [ ] /run
52.0 KiB [ ] /tmp
e 16.0 KiB [ ] /lost+found
8.0 KiB [ ] /snap
e 4.0 KiB [ ] /srv
e 4.0 KiB [ ] /mnt
e 4.0 KiB [ ] /media
e 4.0 KiB [ ] /home
. 0.0 B [ ] /proc
0.0 B [ ] /sys
0.0 B [ ] /dev
@ 0.0 B [ ] libx32
@ 0.0 B [ ] lib64
@ 0.0 B [ ] lib32
@ 0.0 B [ ] sbin
@ 0.0 B [ ] lib
@ 0.0 B [ ] bin
Using Built-In find
or du
Command
#
If you cannot install additional tools like ncdu
or prefer using built-in commands, find is a simple way to locate large files.
Find the largest files above 100M #
To find all files larger than 100 MB, use:
find . -type f -size +100M
Example output:
root@exampleserver:/# find . -type f -size +100M
./usr/bin/dockerd
./proc/kcore
find: ‘./proc/2148186/task/2148186/fdinfo/6’: No such file or directory
find: ‘./proc/2148186/fdinfo/5’: No such file or directory
./var/lib/docker/overlay2/63d159cd9e43c8f18f469b303a0ae948de09c1236de3f67e456e4dbf415c8ba1/diff/var/log/clickhouse-server/clickhouse-server.log
./var/lib/docker/overlay2/63d159cd9e43c8f18f469b303a0ae948de09c1236de3f67e456e4dbf415c8ba1/merged/usr/bin/clickhouse-library-bridge
./var/lib/docker/overlay2/63d159cd9e43c8f18f469b303a0ae948de09c1236de3f67e456e4dbf415c8ba1/merged/usr/bin/clickhouse-odbc-bridge
./var/lib/docker/overlay2/63d159cd9e43c8f18f469b303a0ae948de09c1236de3f67e456e4dbf415c8ba1/merged/usr/bin/clickhouse
./var/lib/docker/overlay2/63d159cd9e43c8f18f469b303a0ae948de09c1236de3f67e456e4dbf415c8ba1/merged/var/log/clickhouse-server/clickhouse-server.log
./var/lib/docker/overlay2/bcd25f48891a843da1fe1f02d0383e7c0545e27ba7e60f3e657ef7390d398b33/diff/usr/local/bin/vector
./var/lib/docker/overlay2/125c13c2320aadc87a0db5be01e4d9f42d1e201e1a7a59d83eb667c724071890/diff/usr/lib/libLLVM-15.so
./var/lib/docker/overlay2/a8d58951db807191267fd3a495ef741f8cc88501e5edc4c08d2704b98c075349/diff/usr/share/grafana/bin/grafana
./var/lib/docker/overlay2/01393d25a1d39c8f3088d921a35894d6cb784d94f90d278e526bab73486719f3/merged/usr/lib/libLLVM-15.so
./var/lib/docker/overlay2/124dbf7640cc4b292c1c26c2e65bf6485903f920941da092a63bae07e739a2f7/diff/usr/local/lib/python3.11/site-packages/sentry_relay/_lowlevel__lib.so
./var/lib/docker/overlay2/1f4a9fcabcb43bf36710172e8615d2dfa2982766cf5f4569af3b3d74941d31eb/diff/usr/bin/clickhouse-library-bridge
./var/lib/docker/overlay2/1f4a9fcabcb43bf36710172e8615d2dfa2982766cf5f4569af3b3d74941d31eb/diff/usr/bin/clickhouse-odbc-bridge
./var/lib/docker/overlay2/1f4a9fcabcb43bf36710172e8615d2dfa2982766cf5f4569af3b3d74941d31eb/diff/usr/bin/clickhouse
./var/lib/docker/overlay2/61320f461c70c394cd01736f4d5580c8032942c819faf24366f03ee267e7ad43/diff/opt/relay-debug.zip
./var/lib/docker/overlay2/b6e39afd230cb1d232383e1c00b7ee723aa93112ada4946cbedbc0b6af472d1c/diff/otelcol-contrib
./var/lib/docker/overlay2/ee1e533f02f49e2cf7f47ad22e9042472eedbba177909c650cab7c27569186b9/merged/usr/local/bin/vector
./var/lib/docker/overlay2/8452045e583209cca83bb8d7db01b4f394593da522382f3a81a637a41f69521d/diff/usr/bin/clickhouse-library-bridge
./var/lib/docker/overlay2/8452045e583209cca83bb8d7db01b4f394593da522382f3a81a637a41f69521d/diff/usr/bin/clickhouse-odbc-bridge
./var/lib/docker/overlay2/8452045e583209cca83bb8d7db01b4f394593da522382f3a81a637a41f69521d/diff/usr/bin/clickhouse
./var/lib/docker/overlay2/a43ef38ddfb0ca00785a2f875fced3bf78f4d75ceba99379f55b072227f2decd/merged/usr/share/grafana/bin/grafana
./var/lib/docker/overlay2/9b98cf491ae37d9df0cb8c54b74fcfcd3046c285f4b86d02e0636edb8a39221e/merged/otelcol-contrib
./var/lib/docker/volumes/uptrace_ch_data9/_data/store/d19/d19a99e3-abe2-4574-97a1-e4024b390ce5/202406_31873_374953_2692/ProfileEvents%2Evalues.bin
./var/lib/docker/volumes/uptrace_ch_data9/_data/store/328/32811309-7f5b-4e24-af9e-5852b8c94d6d/202406_237806_401828_2380/value.bin
./var/lib/docker/volumes/uptrace_ch_data9/_data/store/328/32811309-7f5b-4e24-af9e-5852b8c94d6d/202407_404509_713065_2535/value.bin
Finding the 10 Largest Linux Files on Your Drive #
To find the 10 largest files on your drive, use:
du -aBm / 2>/dev/null | sort -nr | head -n 10
Example output:
root@exampleserver:/# du -aBm / 2>/dev/null | sort -nr | head -n 10
29279M /
26579M /var
22244M /var/lib
22007M /var/lib/docker
11549M /var/lib/docker/volumes
11410M /var/lib/docker/volumes/uptrace_ch_data9/_data/store
11410M /var/lib/docker/volumes/uptrace_ch_data9/_data
11410M /var/lib/docker/volumes/uptrace_ch_data9
10417M /var/lib/docker/overlay2
4218M /var/log
Conclusion #
When dealing with a full disk on Linux, tools like ncdu
provide an interactive, visual approach to finding large files and directories, while built-in commands like find
and du
offer quick solutions without needing to install additional software. Choose the method that best suits your situation.