You are reading the article Using Du To Free Up Disk Space In Linux updated in October 2023 on the website Vibergotobrazil.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested November 2023 Using Du To Free Up Disk Space In Linux
If you’re new to the world of Linux, you may find yourself wondering how to free up disk space. It’s not always as simple as just uninstalling some programs. This is particularly true if you have many files taking up space scattered across your whole filesystem. While there are many different ways to free up disk space in Linux, read on to learn about one of the quickest: using du and some basic terminal commands.What is du? How to Start Using du
You may be wondering how to start using du. The simplest and most basic way is, of course, using the command as is without any options:
However, this isn’t particularly useful information. The output given here is often used by other programs and scripts, but to make it useful for the average user, we will need to include some options.
One such option is to convert the size outputs to a format you can read. To do this, you will need to add either the -h flag or the --human-readable flag.
This makes the size of the files on the left much easier to parse. But there’s still a lot to sort through here. Luckily, some other options make this easier.
The -s flag will summarize the given directory’s disk usage. This is often combined with the -h flag to give a very simple and easy-to-read summary of the directory.
Depending on which directories you’re checking with du, you may need to elevate your privileges using sudo or similar. For example: when you want to see how much disk usage the root directory is using.
While there are many other useful options you can use with du, the -h and -s flags are the only ones we need in order to clean up disk space.How to Free Up Linux Disk Space with du
Now that you know how to use du, you can make use of it when freeing up disk space on your computer.
The quickest way to clean up your disk is to first find out what is using the most space. You can do this by letting du scan the entire system. To do this, you will add an asterisk to the end of the directory path. The asterisk works as a wildcard and tells the command to look at everything in the directory.
This shows you which directory in the filesystem is occupying the most space. From there, you can use the same command in each directory to find out which sub-directories and files are taking up the most space.
In many cases, you will be searching your home directory, as this is where you will store your personal files. You can do this by searching ~/, as this is shorthand for your home directory.
Continue to repeat these commands as much as needed to narrow down which directories are taking up the most space.
For example, if you have a directory called “Storage” in your home folder taking up a lot of space, use du to figure out which files in it are the biggest.
From here, you can simply delete the files you don’t want to use the rm command.
Do this for every other file you no longer want on your drive to free up the desired amount of storage space.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.
You would use df, a completely different command with a very simple usage, to see how much free disk space you have:
-h3. Should I use du to remove programs from my computer?
No, this method is only useful for files you’ve saved yourself. If you want to remove a program, you should use your distribution’s package manager or software center.Wrapping Up
As you can see, freeing up disk space in Linux using the command line is quite simple. Once you have the hang of using du and all its options, you’ll find that it’s also much quicker and easier than most other methods.
But this is just the tip of the iceberg when it comes to commands. Read on to find out which commands to use to search for files in Linux.
Freelance Content Writer with a decade of experience writing about system administration, networking, and security.
Subscribe to our newsletter!
Our latest tutorials delivered straight to your inbox
Sign up for all newsletters.
You're reading Using Du To Free Up Disk Space In Linux
Update the detailed information about Using Du To Free Up Disk Space In Linux on the Vibergotobrazil.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!