If you are looking for a folder that take up the most spaces in your linux, you can use
du command to find them. Let’s try some usecases using
du in linux.
Looking for Big Folder On System Wide
If you are looking for the biggest folder in your linux system, you can use this command:
du -h / | sort -hr | head -n 20
This command will find 20 most biggest folder on your system and sort them from the biggest to smallest. You will see a response like this when you run those command:
If you see some error like those first four lines, you can ignore them.
Looking for a Big Folder in Specific Location
If you are looking for the biggest folder in specific location, you can change the
/ to the location you desired. Let’s see some example. We will run this command to find the biggest folder in
du -h /var | sort -hr | head -n 20
And this is the capture result:
Notice that the result only show folder size inside
/var as we expected.
That’s it! Now you can remove them using this command bellow
rm -rf <folder name>