You download files and install applications to your system. At the same time, your system generates temporary files and writes logs. That eats up your precious disk space, which will be full and wreak havoc on your Linux system if not monitored and managed.

You can remove these unwanted files to reclaim your disk space. Some methods are universal across Linux distributions while some are dependent on the distribution. apt for example is used to manage packages for Ubuntu and Debian derivatives while yum is used for distributions such as RHEL, Fedora and CentOS.

Steps to free up disk space on Linux:

  1. Check disk utilisation on disks and mount points.

    $ df -h Filesystem      Size  Used Avail Use% Mounted on tmpfs           391M  1.9M  389M   1% /run /dev/sda3        20G  7.2G   11G  40% / tmpfs           2.0G     0  2.0G   0% /dev/shm tmpfs           5.0M     0  5.0M   0% /run/lock tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup /dev/sdb         20G   19G   59M 100% /data /dev/sda2       512M  7.9M  505M   2% /boot/efi tmpfs           391M   88K  391M   1% /run/user/126 tmpfs           391M  104K  391M   1% /run/user/1000
  2. Find large files or specific file types that could be deleted for each mount points.

    $ sudo find /data -printf '%s %p\n'| sort -nr | head -10 [sudo] password for user:  19327352832 /data/file.img 471859200 /data/file2.img 3862528 /data/.cache/tracker/meta.db 380901 /data/.cache/gstreamer-1.0/registry.x86_64.bin 363086 /data/.cache/tracker/ontologies.gvdb 346716 /data/.local/share/tracker/data/tracker-store.journal 177047 /data/.cache/ibus/bus/registry 90672 /data/.cache/tracker/meta.db-wal 86016 /data/.local/share/evolution/addressbook/system/contacts.db 75913 /data/.local/share/tracker/data/tracker-store.ontology.journal

  3. Delete large or unnecessary files.

    $ rm /data/file.img /data/file2.img rm: remove write-protected regular file '/data/file.img'? y rm: remove write-protected regular file '/data/file2.img'? y

  4. Check for large user-specific application settings and data directories.

    $ du -hs ~/.[^.]* 4.0K	/home/user/.bash_history 4.0K	/home/user/.bash_logout 4.0K	/home/user/.bashrc 5.1M	/home/user/.cache 160K	/home/user/.config 16K	/home/user/.gnupg 848K	/home/user/.local 452M	/home/user/.npm 4.0K	/home/user/.profile 4.0K	/home/user/.ssh 0	/home/user/.sudo_as_admin_successful

  5. Delete large and unnecessary user-specific application settings and data.

    $ rm -rf /home/user/.npm

  6. Delete home directories of nonexistent users.

    $ sudo rm -rf /home/mike/

  7. Clean up Download or other temporary folders.

    $ rm -rf ~/Downloads/*

  8. Clear Trash folder.

    $ rm -rf ~/.local/share/Trash/files/*

  9. Clear old systemd logs.

    $ sudo journalctl --disk-usage && sudo journalctl --vacuum-time=7d Archived and active journals take up 240.0M in the file system. Vacuuming done, freed 0B of archived journals from /var/log/journal. Deleted archived journal /var/log/journal/38fcf097cda64808aef7af32f0834151/system@852cf4a689e7473a97d0533bafae2054-0000000000000001-0005b27490a208e1.journal (24.0M). Deleted archived journal /var/log/journal/38fcf097cda64808aef7af32f0834151/user-1000@4d0d7c66ddf9410fa446a046657ab3ab-0000000000000a39-0005b274a5669f39.journal (16.0M). Deleted archived journal /var/log/journal/38fcf097cda64808aef7af32f0834151/system@852cf4a689e7473a97d0533bafae2054-0000000000006445-0005b5bf6fba6857.journal (16.0M). Deleted archived journal /var/log/journal/38fcf097cda64808aef7af32f0834151/user-1000@c60606ac0ca3455ca9492b6bd49ce2f2-0000000000006806-0005b5bf7391f30f.journal (8.0M). Deleted archived journal /var/log/journal/38fcf097cda64808aef7af32f0834151/system@852cf4a689e7473a97d0533bafae2054-000000000000a5cd-0005b856a36afa1f.journal (8.0M). Deleted archived journal /var/log/journal/38fcf097cda64808aef7af32f0834151/system@852cf4a689e7473a97d0533bafae2054-000000000000a947-0005b856a5854959.journal (24.0M). Deleted archived journal /var/log/journal/38fcf097cda64808aef7af32f0834151/user-1000@b3fc06a6233f42bb8d482453cf7a92dd-000000000000b4f6-0005b856ba685e8f.journal (16.0M). Deleted archived journal /var/log/journal/38fcf097cda64808aef7af32f0834151/system@852cf4a689e7473a97d0533bafae2054-0000000000011c87-0005baef664f0469.journal (16.0M). Deleted archived journal /var/log/journal/38fcf097cda64808aef7af32f0834151/user-1000@9b15171bb2d8475c815a99f2ddfa2506-0000000000011fc8-0005baef71f8a720.journal (16.0M). Deleted archived journal /var/log/journal/38fcf097cda64808aef7af32f0834151/system@852cf4a689e7473a97d0533bafae2054-0000000000016a5b-0005bd863fbd8a2b.journal (8.0M). Deleted archived journal /var/log/journal/38fcf097cda64808aef7af32f0834151/user-1000@0594db55f9784dd8b3521a652a2b88ec-0000000000016d41-0005bd8640bfaf3d.journal (8.0M). Deleted archived journal /var/log/journal/38fcf097cda64808aef7af32f0834151/user-1000@0594db55f9784dd8b3521a652a2b88ec-0000000000017052-0005bd8642463547.journal (8.0M). Deleted archived journal /var/log/journal/38fcf097cda64808aef7af32f0834151/system@852cf4a689e7473a97d0533bafae2054-0000000000017050-0005bd8641907c49.journal (16.0M). Vacuuming done, freed 184.0M of archived journals from /var/log/journal/38fcf097cda64808aef7af32f0834151. Vacuuming done, freed 0B of archived journals from /run/log/journal.

  10. List installed programs or packages.

    $ sudo apt list --installed # Ubuntu and Debian derivatives   Listing... accountsservice/groovy-updates,groovy-security,now 0.6.55-0ubuntu13.2 amd64 [installed,automatic] acl/groovy,now 2.2.53-8 amd64 [installed,automatic] acpi-support/groovy,now 0.143 amd64 [installed,automatic] acpid/groovy,now 1:2.0.32-1ubuntu1 amd64 [installed,automatic] adcli/groovy-updates,groovy-security,now 0.9.0-1ubuntu1.2 amd64 [installed,automatic] adduser/groovy,groovy,now 3.118ubuntu2 all [installed] adwaita-icon-theme/groovy,groovy,now 3.38.0-1ubuntu1 all [installed,automatic] aisleriot/groovy,now 1:3.22.9-1 amd64 [installed,automatic] alsa-base/groovy,groovy,now 1.0.25+dfsg-0ubuntu5 all [installed,automatic] ##### snipped
    $ rpm -qa # RHEL, Fedora, CentOS and Red Hat derivatives sysstat-11.7.3-5.el8.x86_64 plymouth-scripts-0.9.4-7.20200615git1e36e30.el8.x86_64 fontpackages-filesystem-1.44-22.el8.noarch file-libs-5.33-16.el8_3.1.x86_64 ipset-libs-7.1-1.el8.x86_64 libdnf-0.48.0-5.el8.x86_64 publicsuffix-list-dafsa-20180723-1.el8.noarch systemd-239-41.el8_3.2.x86_64 python3-rpm-4.14.3-4.el8.x86_64 emacs-filesystem-26.1-5.el8.noarch ##### snipped

  11. Remove unnecessary program or packages.

    $ sudo apt remove --assume-yes libreoffice-* # Ubuntu and Debian derivatives  Reading package lists... Done Building dependency tree        Reading state information... Done Note, selecting 'libreoffice-wiki-publisher' for glob 'libreoffice-*' Note, selecting 'libreoffice-style-breeze' for glob 'libreoffice-*' Note, selecting 'libreoffice-math' for glob 'libreoffice-*' Note, selecting 'libreoffice-report-builder-bin-nogui' for glob 'libreoffice-*' Note, selecting 'libreoffice-l10n-gug' for glob 'libreoffice-*' Note, selecting 'libreoffice-script-provider-js' for glob 'libreoffice-*' Note, selecting 'libreoffice-report-builder-bin' for glob 'libreoffice-*' Note, selecting 'libreoffice-grammarcheck' for glob 'libreoffice-*' Note, selecting 'libreoffice-mysql-connector' for glob 'libreoffice-*' ##### snipped The following packages were automatically installed and are no longer required:   gstreamer1.0-gtk3 libabw-0.1-1 libboost-date-time1.71.0 libboost-filesystem1.71.0 libboost-iostreams1.71.0 libboost-locale1.71.0 libcdr-0.1-1 libclucene-contribs1v5 libclucene-core1v5 libcmis-0.5-5v5 libcolamd2   libe-book-0.1-1 libeot0 libepubgen-0.1-1 libetonyek-0.1-1 libexttextcat-2.0-0 libexttextcat-data libfreehand-0.1-1 libgpgmepp6 libjuh-java libjurt-java liblangtag-common liblangtag1 liblibreoffice-java libmhash2   libmspub-0.1-1 libmwaw-0.3-3 libmythes-1.2-0 libneon27-gnutls libodfgen-0.1-1 liborcus-0.15-0 liborcus-parser-0.15-0 libpagemaker-0.0-0 libraptor2-0 librasqal3 librdf0 librevenge-0.0-0 libridl-java   libsuitesparseconfig5 libuno-cppu3 libuno-cppuhelpergcc3-3 libuno-purpenvhelpergcc3-3 libuno-sal3 libuno-salhelpergcc3-3 libunoloader-java libvisio-0.1-1 libwpd-0.10-10 libwpg-0.3-3 libwps-0.4-4 libxmlsec1-nss   libyajl2 lp-solve uno-libs-private ure Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED:   libreoffice-base-core libreoffice-calc libreoffice-common libreoffice-core libreoffice-draw libreoffice-gnome libreoffice-gtk3 libreoffice-help-common libreoffice-help-en-us libreoffice-impress libreoffice-math   libreoffice-ogltrans libreoffice-pdfimport libreoffice-style-breeze libreoffice-style-colibre libreoffice-style-elementary libreoffice-style-yaru libreoffice-writer python3-uno 0 upgraded, 0 newly installed, 19 to remove and 24 not upgraded. After this operation, 360 MB disk space will be freed. ##### snipped  
    $ sudo yum remove --assumeyes nmap # RHEL, Fedora, CentOS and Red Hat derivatives Dependencies resolved. ============================================================================================================================================================================================================================================================  Package                                                  Architecture                                               Version                                                           Repository                                                      Size ============================================================================================================================================================================================================================================================ Removing:  nmap                                                     x86_64                                                     2:7.70-5.el8                                                      @appstream                                                      24 M  Transaction Summary ============================================================================================================================================================================================================================================================ Remove  1 Package  Freed space: 24 M Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction   Preparing        :                                                                                                                                                                                                                                    1/1   Erasing          : nmap-2:7.70-5.el8.x86_64                                                                                                                                                                                                           1/1   Running scriptlet: nmap-2:7.70-5.el8.x86_64                                                                                                                                                                                                           1/1   Verifying        : nmap-2:7.70-5.el8.x86_64                                                                                                                                                                                                           1/1 Installed products updated.  Removed:   nmap-2:7.70-5.el8.x86_64  Complete!

  12. Remove unused package dependencies.

    $ sudo apt autoremove # Ubuntu and Debian derivatives  Reading package lists... Done Building dependency tree        Reading state information... Done The following packages will be REMOVED:   gstreamer1.0-gtk3 libabw-0.1-1 libboost-date-time1.71.0 libboost-filesystem1.71.0   libboost-iostreams1.71.0 libboost-locale1.71.0 libcdr-0.1-1 libclucene-contribs1v5   libclucene-core1v5 libcmis-0.5-5v5 libcolamd2 libe-book-0.1-1 libeot0 libepubgen-0.1-1   libetonyek-0.1-1 libexttextcat-2.0-0 libexttextcat-data libfreehand-0.1-1 libgpgmepp6 libjuh-java   libjurt-java liblangtag-common liblangtag1 liblibreoffice-java libmhash2 libmspub-0.1-1   libmwaw-0.3-3 libmythes-1.2-0 libneon27-gnutls libodfgen-0.1-1 liborcus-0.15-0   liborcus-parser-0.15-0 libpagemaker-0.0-0 libraptor2-0 librasqal3 librdf0 librevenge-0.0-0   libridl-java libsuitesparseconfig5 libuno-cppu3 libuno-cppuhelpergcc3-3 libuno-purpenvhelpergcc3-3   libuno-sal3 libuno-salhelpergcc3-3 libunoloader-java libvisio-0.1-1 libwpd-0.10-10 libwpg-0.3-3   libwps-0.4-4 libxmlsec1-nss libyajl2 linux-headers-5.8.0-44 linux-headers-5.8.0-44-generic   linux-image-5.8.0-44-generic linux-modules-5.8.0-44-generic linux-modules-extra-5.8.0-44-generic   lp-solve uno-libs-private ure 0 upgraded, 0 newly installed, 59 to remove and 29 not upgraded. After this operation, 435 MB disk space will be freed. Do you want to continue? [Y/n] ##### snipped
    $ sudo yum autoremove --assumeyes # RHEL, Fedora, CentOS and Red Hat derivatives Last metadata expiration check: 0:00:39 ago on Thu 15 Apr 2021 10:20:13 PM EDT. Dependencies resolved. ============================================================================================================================================================================================================================================================  Package                                                  Architecture                                   Version                                                                                   Repository                                          Size ============================================================================================================================================================================================================================================================ Removing:  fipscheck                                                x86_64                                         1.5.0-4.el8                                                                               @anaconda                                           47 k  fipscheck-lib                                            x86_64                                         1.5.0-4.el8                                                                               @anaconda                                           12 k  grub2-tools-efi                                          x86_64                                         1:2.02-90.el8_3.1                                                                         @baseos                                            2.0 M  libdnet                                                  x86_64                                         1.12-26.el8                                                                               @AppStream                                          79 k  mozjs52                                                  x86_64                                         52.9.0-2.el8                                                                              @BaseOS                                             23 M  oci-systemd-hook                                         x86_64                                         1:0.1.15-2.git2d0b8a3.module_el8.1.0+237+63e26edc                                         @AppStream                                          74 k  ostree-libs                                              x86_64                                         2020.5-4.el8                                                                              @AppStream                                         1.0 M  yajl                                                     x86_64                                         2.1.0-10.el8                                                                              @AppStream                                          85 k  Transaction Summary ============================================================================================================================================================================================================================================================ Remove  8 Packages  Freed space: 26 M Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. ##### snipped

  13. Remove unused package installer files.

    $ sudo apt clean # Ubuntu and Debian derivatives
    $ sudo yum clean all # RHEL, Fedora, CentOS and Red Hat derivatives 36 files removed

  14. Look for old system and application logs.

    $ ls /var/log/ alternatives.log       boot.log.5     dpkg.log.3.gz    private               vmware-network.4.log alternatives.log.1     boot.log.6     dpkg.log.4.gz    speech-dispatcher     vmware-network.5.log alternatives.log.2.gz  boot.log.7     dpkg.log.5.gz    sssd                  vmware-network.6.log alternatives.log.3.gz  bootstrap.log  faillog          syslog                vmware-network.7.log alternatives.log.4.gz  btmp           fontconfig.log   syslog.1              vmware-network.8.log alternatives.log.5.gz  btmp.1         gdm3             syslog.2.gz           vmware-network.9.log apt                    cups           gpu-manager.log  syslog.3.gz           vmware-network.log auth.log               dist-upgrade   hp               syslog.4.gz           vmware-vmsvc-root.1.log auth.log.1             dmesg          installer        syslog.5.gz           vmware-vmsvc-root.2.log auth.log.2.gz          dmesg.0        journal          syslog.6.gz           vmware-vmsvc-root.3.log auth.log.3.gz          dmesg.1.gz     kern.log         syslog.7.gz           vmware-vmsvc-root.log auth.log.4.gz          dmesg.2.gz     kern.log.1       sysstat               vmware-vmtoolsd-root.log boot.log               dmesg.3.gz     kern.log.2.gz    ubuntu-advantage.log  wtmp boot.log.1             dmesg.4.gz     kern.log.3.gz    unattended-upgrades boot.log.2             dpkg.log       kern.log.4.gz    vmware-network.1.log boot.log.3             dpkg.log.1     lastlog          vmware-network.2.log boot.log.4             dpkg.log.2.gz  openvpn          vmware-network.3.log

  15. Remove old and unnecessary system and application logs.

    $ sudo rm /var/log/*[3-9].*