Introduction

Often times, a situation arises when the linux based system is running low on disk space. How to clear some disk space in a quick and easy way? Lets take a look.

  1. First check the remaining free space on the Ubuntu Server.

    free -h

    free

    Now we will free up the disk space in Ubuntu

  2. Get rid of packages that are no longer required.

    Command autoremove. This option removes libs and packages that were installed automatically to satisfy the dependencies of an installed package. If that package is removed, these automatically installed packages are useless in the system.

    It also removes old Linux kernels that were installed automatically in the system upgrade.

    sudo apt-get autoremove
  3. Uninstall unnecessary applications.

    You can  remove a program in Ubuntu Server with the use of the following command.

    sudo apt-get remove package-name1 package-name2
  4. Clean up APT cache in Ubuntu.

    Ubuntu uses  APT (Advanced Package Tool) for installing, removing and managing software on the system, and in doing so it keeps a cache of previously downloaded and installed packages even after they’ve been uninstalled.

    The APT package management system keeps a cache of DEB packages in /var/cache/apt/archives. Over time, this cache can grow quite large and hold a lot of packages you don’t need.

    You can see the size of this cache with the du command below:

    sudo du -sh /var/cache/apt

    free1

    In our case this is not too much. However, incase it is too much for example more than 50MB then , we have 2 ways to clean the APT cache.

    Either remove only the outdated packages, like those superseded by a recent update, making them completely unnecessary.

    sudo apt-get autoclean

    Or delete entire apt cache. This will frees more disk space.

    sudo apt-get clean
  5. Clear systemd journal logs.

    Every Linux distribution has a logging mechanism that helps you investigate what’s going on in your system. You’ll have kernel logging data, system log messages, standard output and errors for various services in Ubuntu.

    The problem is that over time, these logs take a considerable amount of disk space. You can check the log size with this command:

    sudo journalctl --disk-usage

    sudo journal

    Now, there are ways to clean systemd journal logs. The easiest for you is to clear the logs that are older than certain days.

    sudo journalctl --vacuum-time=3d
  6. Clean the thumbnail cache.

    Ubuntu automatically creates a thumbnail, for viewing in the file manager. It stores those thumbnails in a hidden directory in your user account at the location ~/.cache/thumbnails.

    Over time, the number of thumbnails would increase dramatically. Moreover, the thumbnail cache will eventually contain many superfluous thumbnails of pictures that don’t exist anymore.

    You can check the size of the thumbnail cache with the command below:

    du -sh ~/.cache/thumbnails

    So it’s a good practice to clear the thumbnail cache every few months or so.

  7. Clear NPM cache

    If npm is installed, then cache can be using a lot of space. It is always good to clear the cache. This can be done using the following command.

    npm cache clean --force
  8. Deleting old items from .cache

    You can delete files or directories which are older than 1 Year (or 30 days, in that case just adjust atime +30)

    find ~/.cache/ -type f -atime +365 -delete

---

Appendix

For detailed info, please refer this really informative blog:

https://itsfoss.com/free-up-space-ubuntu-linux/

Copyright © thesmartbug.com | 2024