Computer paradigms

Reclaim disk space on an Ubuntu server

Commands to reduce disk space occupied by obsolete files

Find large files and directories

View disk space with NCDU

NCDU is a software which display the list of directories and their respective volumes. It is very practical to visualize at a glance what consumes space.

To install it :

apt install ncdu

Then directly :


The software browses all the directories and sub-directories of the current directory (you can also do "ncdu /" to do it from the whole disk) then will display the result of its analysis, in decreasing size. You can browse the directories to find those that you think are too large.

To display modification dates, run ncdu with the "-e" argument, then in the tree structure, press the m key to toggle the display.

GDU is a clone of NCDU. To install it:

curl -L https://github.com/dundee/gdu/releases/latest/download/gdu_linux_amd64.tgz | tar xz
chmod +x gdu_linux_amd64
sudo mv gdu_linux_amd64 /usr/bin/gdu

Show the 10 largest files

From the current directory and its sub-directories:

find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

The 10 largest directories

From the current directory and its sub-directories:

find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}

Delete directories and files that are no longer needed

Clean the operating system

To clear the cache of stale packages, clear the entire cache, fix broken dependencies, and remove packages installed as dependencies and no longer needed in one command:

apt-get autoclean && sudo apt-get clean && apt-get -f install && apt-get autoremove

Reduce the log file size

Modifiez le fichier de configuration du journal :

nano /etc/systemd/journald.conf

And activate the following line:


Purge MySQL logs

If you use the MySQL DBMS, by default it creates a lot of log files. Try to clean them with this article : Avoid too large MySQL logs.

Vider le cache

Show disk cache size:

du -h --summarize ~/.cache

Delete files older than 6 months:

find ~/.cache -type f -mtime +180 -delete
Dernière modification le 18/03/2021 - Quillevere.net


No inscription needed if you wish to

Search in this website

fr en rss RSS info Informations