How to Find Directories/Files That Take up the Most Disk Space in Linux: A Step-by-Step Tutorial

How to Find Directories/Files That Take up the Most Disk Space in Linux: A Step-by-Step Tutorial

Let’s find out how to check disk space usage in Linux and how to find out what files use most of the disk space. I will use Ubuntu 22.04 distribution in this tutorial.


The df command displays information about total and available space on a file system. h stand for human-readable (print sizes in powers of 1024).

Here in this example picture, you can see that /dev/root using 1.8GB of space.

Article content

Let’s check which files take up the most space.

We will use the du command for that. du command summarizes the disk usage of the set of FILEs, recursively for directories.

The full command that I love to use is the following:

sudo du -hsx /* | sort -rh | head -n 10        

I use sudo because some files owned by sudo users only.

du = summarizes the disk usage.

-h = human readable, print sizes in human readable format.

-s = summarize, display only a total for each argument.

-x = one-file-system, skip directories on different file systems.

/* = start from the root folder and include all files.

sort -rh = compare human readable numbers and reverse the result of comparisons (place the biggest size on top of the output).

head -n 10 = Print the first 10 lines of each FILE to standard output. Actually the first 10 lines is the default value for head command, so you don’t have to write -n 10after the head. I wrote it for visibility only.

When I execute this command on my server, here is the output I got:

Article content

I see the /usr directory takes the most of the disk space.

The next step will be to run the same command in the /usr directory.

sudo du -hsx /usr/* | sort -rh | head -n 10        
Article content

I see that /usr/lib takes the most of the disk space.

The next step will be to run the same command in the /usr/lib directory.

sudo du -hsx /usr/lib/* | sort -rh | head -n 10        
Article content

I see that /usr/lib/x86_64-linux-gnu takes the most of the disk space.

The next step will be to run the same command in the /usr/lib/x86_64-linux-gnu directory.

sudo du -hsx /usr/lib/x86_64-linux-gnu/* | sort -rh | head -n 10        
Article content

You get the idea. You start in the root directory and dig until you find files that take up disk space.

My Ubuntu server is a fresh installation, so there are no much files there.

In real-world cases, these may be Docker or Kubernetes-related files (cache, unnecessary images, containers, volumes, etc.) that take up the most disk space. Maybe some old logs as well.

Be careful when you clean the “unnecessary files.” You must know exactly what you are doing.


To view or add a comment, sign in

More articles by Andrey Byhalenko

Insights from the community

Others also viewed

Explore topics