After few months or years later, you will notice unnecessary files, libraries and/or documentation eating up your disk space On Debian or Ubuntu Linux. Try the following tips to free up disk space.
Remove cached .deb files
When you run apt-get command, it downloads and caches the package in /var/cache/apt/archives directory. cd into this directory:
# cd /var/cache/apt/archives
# du â€“ch
8.0K ./partial 838M . 838M total
Remove all cached *.deb files using the following rm command:
# rm â€“f *.deb
Remove Orphaned package
The deborphan command finds packages that have no packages depending on them. The default operation is to search only within the libs and oldlibs sections to hunt down unused libraries. The following command displays orphaned package list:
$ deborphan -sz
- -s: Show the sections the packages are in.
- -z: Show the installed size of the packages found.
You can remove orphaned package with apt-get command remove option:
# apt-get remove packagename
Alternatively, remove all orphaned package in a single command, type:
# apt-get remove $(deborphan)
# apt-get remove --purge $(deborphan)
If you find command line hard to use try orphaner command which is nothing but a neat frontend for deborphan displaying a list of orphaned packages with dialog or whiptail. Packages may be selected for removal with apt-get which is then called to do the work. After removal a new list of orphaned packages is gathered from deborphan. The program ends when either “Cancel” is pressed or no package is marked for removal.
However some packages are important and if you want to keep them forever, use editkeep command which is a frontend for deborphan displaying a list of orphaned packages (-a for all-sections is implied) and packages which are tagged to never been shown using dialog or whiptail:
cruft is a program that goes over the Debian packaging system’s database, and compares the contents of that with the files actually on your system, and produces a summary of the differences. For example, you can clean spool with following command:
# cruft â€“k
Read the cruft man page for advance usage.
Remove log files
Backup log files and remove them from /var/log directory. To truncate log file you can run for loop:
# cd /var/log/squid
# for i in *; do >$i; done
Also, consider rotating log files using logroate facility.
- Linux: Debian package management cheat sheet
- How do I rotate log files?
- Read the man pages for: apt-get(8) commands.
|Category||List of Unix and Linux commands|
|Firewall||CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04|
|Network Utilities||dig • host • ip • nmap|
|OpenVPN||CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04|
|Package Manager||apk • apt|
|Processes Management||bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time|
|Searching||grep • whereis • which|
|User Information||groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w|
|WireGuard VPN||CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04|