How to Find the Largest Files and Directories on Debian

Ever experienced the frustration of a server running out of storage space? It can be difficult to locate the problem, unless you have THE command to investigate. 😎

1 min read
How to Find the Largest Files and Directories on Debian
Photo by Tima Miroshnichenko on Pexels.

Running out of server space can be a real headache, often requiring thorough investigation to pinpoint the issue. In this quick guide, I'll show you an invaluable command that can help you identify the culprits behind excessive storage consumption on your Debian server.

To uncover the largest files and directories eating up your server's precious space, you can employ the following command:

sudo du --all / | sort --numeric-sort --reverse | head --lines 15

Or alternatively:

sudo du -a / | sort -n -r | head -n 15

The output of this command provides a list of the largest files and directories, accompanied by the space they occupy:

25072264  /
20175684  /var
8949680   /var/lib
8783876   /var/lib/docker
8629384   /var/lib/docker/overlay2
6131060   /var/log
[...]
An example of the output of the previous command.

This resulted list helped me to swiftly identify the storage-intensive elements on my server. Armed with this knowledge, I implemented measures to mitigate their impact and free up valuable space.

Should you need to delve into a specific directory for a more thorough investigation, the command can be tailored accordingly. For instance, if you want to focus on the /var/log directory:

sudo du -a /var/log | sort -n -r | head -n 15

By integrating this command into your diagnostic toolkit, you can confidently tackle storage issues and prevent future space shortages on your server. The satisfaction of maintaining an organized and efficient server environment awaitsβ€”enjoy the journey! 😎