Keep your system clean with linux
I monitor my system disk usage a lot and lately, 90% of the space was used. This needs spring cleanup! I use a partition for /
(30GB) and one for /home
(466GB).
# Docker
Docker has a special directory at /home/docker
, for this to work add this to /etc/docker/daemon.json
:
{"data-root": "/home/docker"}
To clean up docker usage, there are prune commands for images, volumes and networks. You may want to stop and remove running containers first:
# Kill all running containers
docker kill $(docker ps -q)
# Delete all stopped containers
docker rm $(docker ps -a -q)
For the volumes (warning: potential data loss):
docker volume prune
Works also for networks:
docker network prune
And for images:
docker image prune
# System
I use NCurses Disk Usage to find what’s using space, to inspect my root partition I’m using:
ncdu --exclude /home /
In doing so you’ll often find out that the space is used by:
- caches
- logs
- documentation
First clean your /tmp
directory using rm -r /tmp/*
. Then the logs:
# Keep latest log under 50M
journalctl --vacuum-size=50M
# or purge by date
journalctl --vacuum-time=4weeks
You can custom default values in the journald.conf file see man journald.conf
. I like to keep the defaults and to clean manually from time to time.
My /home
directory will hold a rather big ~/.cache
directory. I usually keep these as it is used by: browsers, spotify, npm, composer etc.
The /var/cache
directory may also hold big directories, I removed the pkgfile
cache.
For the documentation they may be removed by removing the packages or manually in the /usr/share/doc/
directory.
# Pacman
Remove unused packages:
pacman -Qtdq | pacman -Rns -
Delete the pacman cache:
# Remove the cache for non-installed packages
pacman -Sc
# Remove all the cache
pacman -Scc
There are nice Pacman tips and tricks on archlinux.org, make sure to check this page.
# Useful commands
# List disks
fdisk -l
# File system disk space usage
df -h
# check your partitions
parted
> print all
Sources: