Utilitaires
Scripts
Divers
Jeux
Rechercher
Quillevere.net
Computer science thoughts

Reclaim disk space on an Ubuntu server

18/03/2021
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 :

ncdu

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.

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:

SystemMaxUse=100M

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.

Dernière modification le 19/03/2021 - Quillevere.net

Articles connexes

Search in this website

fr en rss RSS info Informations