How to Get Size of Directory in Linux

how to find disk usage of directories in linux

In this article, we focus on how you can check the size of Directory on Linux Systems. This we are going to achieve using the command line interface.

The command used to retrieve the file sizes is the du command, short for disk usage.

The syntax for du usage is

du [OPTION]... [FILE] [directory]

Check Size of a Directory

To find out the size of a directory run

# du -sh

Let's break this command down further

-s , --summarize -  Displays only a total for each argument
-h , --human-readable - This prints the sizes in a human readable format. e.g 50G , 285M

For example, to get the size of a directory, run

# du -sh directory_name/

In this case, I have a directory called 'django' in my current working directory. To find its size, I ran,

# du -sh /django

Sample Output

252M    django/

Display Directory size in KB/MB or GB

You can also decide to display disk usage size in Kb, MB or GB.

To accomplish this simply use -k for kilobytes, and -m for megabytes. Using our sample directory, the syntax will be

# du -k django/

Sample Output

find the disk usage of Directory and Sub Folders

To display the usage in Megabytes run,

# du -m django

Sample Output

find the disk usage of Directory and Sub Folders

As you may have noticed, the commands only display the disk usage of the directory but not the file sizes. To display the file sizes, use the -a flag as shown. the -a flag specifies all files and directories

# du -ah /django

Sample output

find the disk usage of Directory and Sub Folders

Find Total Directory Usage

To view the grand total usage of all files and directories in your directory, append the -c flag as shown

# du -csh django/


252M django/
252M total

find the disk usage of Directory and Sub Folders

If you want to display only the grand total of a  given directory including all the sub-directories, use grep command with ‘du’ command like below.

# du -ch django | grep  docs

Sample Output

find disk usage of a specific directory

Find Sub Folder Disk Usage

To show which subfolders take up disk space. Run below command

# du -h --max-depth=1 | sort -hr

Sample Output

For more information about the du command run

# man du

That's all we had for you folks. We hope you found this tutorial helpful. Keep tuned in for more helpful topics.

Read Also:

2 Comments... add one

  1. I use this command all the time to report direcory usage for departments that do not have a clue what folder contains what. I use the command in a alias i created: alias dus1='du -xh --max-depth=1 | sort -h'
    This reports all folders (max 1 level deep) in human readable format and sort the by size (biggest at the end) so you have a good overview of biggest used folders.


Leave a Comment