cleanup disk space linux

How to Clean Up Disk Space in Linux

Often you may need to free up disk space on your Linux system to make your programs and processes run faster, and avoid problems of running out of disk space. In this article, we will look at several useful ways to clean up disk space in Linux. There is no single command or readymade tool to help you free up disk space. It is a combination of commands that will help you identify and clean up your disk.


How to Clean Up Disk Space in Linux

Here are the steps to clean up disk space in Linux. You can use these steps on almost all distributions.


1. Delete Big files

The most basic strategy is to identify and delete any unnecessary files that consume lot of space. Here is how to go about it. Go to root folder.

$ cd /

List folders by size.

$ sudo du -h --max-depth=1

Note biggest directories. cd into any of the big directories

Run ls -l command to list all its files and folders. Delete the ones you don’t need.

Repeat these steps for other folders listed in the output of du command above.


2. Remove unnecessary packages

You can remove unnecessary packages from your system with the following command. It will automatically remove unused packages from your system.

$ sudo apt-get autoremove


3. Remove unnecessary applications

You may also manually remove unnecessary packages & applications using the following command. Replace <package_name> with name of package you want to delete.

$ sudo apt-get remove <package_name>


4. Clean up apt-cache in Ubuntu

If you are using Ubuntu/Debian system, then you should note that apt-get command uses a cache of previously downloaded & installed packages on your system. It is located at /var/apt/cache and grows over time as you install/update more and more packages on your system. Run the following command to clear it.

$ sudo du -sh /var/cache/apt 

You may also use any of the following commands to accomplish the same.

$ sudo apt-get autoclean
OR
$ sudo apt-get clean


5. Clean up System Logs

Every Linux system logs different kinds of information such as system messages, standard output and errors of various services in Ubuntu. Over time, these logs grow as your system activity increase and take up a lot of space if left unchecked. Here is the command to view the size of your system log.

$ sudo journalctl --disk-usage

Here is the command to restrict your system to log only information for up to past 3 days. You may change the timeframe as your requirement by modifying ‘3d’ in the following command.

$ sudo journalctl --vacuum-time=3d


In this article, we have looked at different ways to clean up disk space in Linux. As mentioned earlier, you will need to free up space, part by part, using a set of commands. There is not single command or tool that automatically identifies all unused programs, files and applications and deletes them. The above list is not exhaustive but it will help you free up substantial amount of disk space quickly.

Also read:

How to Add Response Header in NGINX
How to Redirect Parent Folder in Apache
How to List Open Ports in Linux
How to Rewrite URL to Subdirectory in Apache
How to Rewrite URL with Parameters in Apache

2 thoughts on “How to Clean Up Disk Space in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *