How To Free Linux Disk Space

Running out of disk space is a common issue that Linux users encounter. It can even prevent some applications from functioning properly. The good news is, Linux provides several commands and tools that can help you free up disk space. In this blog, we will look at some of these commands and how you can use them effectively.

Using the ‘df’ Command

Before you start freeing up disk space, it’s necessary to identify how much disk space is being used and what’s consuming it. One of the most useful commands for this purpose is the ‘df’ command which stands for disk filesystem.

Here is an example of how to use the ‘df’ command:

$ df -h

This command will display the amount of disk space used and available on your Linux file systems. The ‘-h’ option makes the output easier to comprehend by displaying the size in ‘human-readable’ format (e.g., K for kilobytes, M for megabytes, G for gigabytes, etc.).

Using the ‘du’ Command

Another useful command is the ‘du’ command, which stands for disk usage. This command is used to estimate file and directory space usage. The command ‘du -sh’ will give you a summary, in human-readable format, of the disk usage in the current directory:

$ du -sh

Remove Unnecessary Packages and Dependencies

Over time, you may install packages that are no longer needed or that have unused dependencies. The following commands can be used to remove unnecessary packages and dependencies:

$ sudo apt-get autoremove
$ sudo apt-get clean

Both commands are used in conjunction. The ‘autoremove’ command removes packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed. The ‘clean’ command clears out the local repository of retrieved package files, freeing up disk space.

Delete Old Kernels

Each time you update your system’s kernel, the old version remains on the disk. If you do not manually delete it, it will take up disk space. You can safely remove old kernels using the following commands:

$ sudo apt-get autoremove --purge

Remember to be cautious when deleting kernels. Do not delete the currently used kernel. You can check your current kernel version by running the command:

$ uname -r

In conclusion, disk space management is an essential part of maintaining a Linux system. Regularly using the above-mentioned commands can ensure your system continues to run smoothly. Remember always to check what you are removing to avoid deleting important files.