If you’re new to Linux, you might be asking how to make more space on your hard drive. It’s not usually as straightforward as deleting a few apps. This is especially true if you have a large number of files dispersed over your whole disk. While there are a variety of ways to free up disk space in Linux, keep reading to learn about one of the quickest: du and a few basic terminal commands.
What is du?
In Linux, du is a typical command that displays information about disk utilization fast. The command’s name literally means “disk usage.” While this may appear to be a simple command, du has a variety of parameters and functions that make it a useful tool for both novice and advanced Linux users.
How to Start Using du
You might be unsure how to get started with du. Using the command without any parameters is, of course, the simplest and most basic method:
du
This, on the other hand, isn’t especially relevant knowledge. Other programs and scripts frequently use the output provided here, but we’ll need to add some parameters to make it usable for the typical user.
Converting the size outputs to a format you can read is one possibility. You’ll need to use the -h or –human-readable flags to accomplish this.
du -h

The size of the files on the left is more easier to interpret as a result of this. However, there is still a lot to sort through. Other solutions, fortunately, make this easier.
The -s flag displays a summary of the disk utilization of the specified directory. This is frequently used in conjunction with the -h switch to provide a quick and easy-to-read overview of the directory.
du -hs

Depending on which folders you’re inspecting with du, you might need to use sudo or something similar to boost your rights. When you want to see how much disk space the root directory takes up, for example.
While du has many other useful options, the -h and -s flags are the only ones we need to free up disk space.
Related: How to Clean Up and Make Space on Your Windows “C” Drive
How to Free Up Linux Disk Space with du
You may use du to free up disk space on your computer now that you know how to use it.
Finding out what is taking up the most space on your disk is the quickest approach to clean it up. This can be accomplished by allowing du to scan the entire system. To accomplish this, append an asterisk to the directory path. The asterisk acts as a wildcard, instructing the command to look through the entire directory.
sudo du -hs /*

This displays the directory in the filesystem that takes up the most space. Then, in each directory, use the same command to see which sub-directories and files are using up the most space.
In most circumstances, you’ll be looking in your home directory, as this is where your personal files are kept. This can be done by searching for ~/
, which stands for your home directory.
du -hs ~/*

Repeat these commands as many times as necessary to determine which directories are using up the most space.
For example, if your home folder has a subfolder called “Storage” that is using up a lot of space, du can help you figure out which files in it are the largest.
du -hs ~/Storage/*
Using the rm command, you can simply delete the files you don’t want.
rm -rf ~/Storage/big-file
To free up the desired quantity of storage space, repeat the process for any other files you no longer want on your drive.
Related: How to Combine PDF Files on Windows and Linux
Frequently Asked Questions
1. Is there a way to sort by file size?
Yes, you can pipe the output from du
into sort
in order to sort by file size.
du -hs ~/* | sort -hr
2. How do I see how much free disk space I have?
To view how much free disk space you have, you’d use df, a whole separate tool with a very easy usage:
df -h
3. Should I use du to remove programs from my computer?
No, this method only works with files that you have saved yourself. If you want to uninstall a program, utilize the package manager or software center in your distribution.
Related: How to Set Process Priority in Task Manager on Windows 10
Final Thoughts
As you can see, utilizing the command line to free up disk space in Linux is pretty straightforward. You’ll discover that using du and all of its capabilities is considerably faster and easier than most other ways once you get the hang of it.
No Responses