Home Linux Commands How To Find The Size Of A Directory In Linux

How To Find The Size Of A Directory In Linux

Du Command Examples For Beginners

By sk
Published: Last Updated on 152.7K views

This brief tutorial explains how to find the size of a directory in Linux operating systems. Finding the size of files and directories in graphical mode is very easy! All we have to do is just right click on the file or directory, and choose the properties option from the context menu. However, it is equally important to know how to check directory size from CLI mode as well.

Find the size of a directory in Linux

We can get the directory size using 'du' command in Linux and Unix-like operating systems. The du command will estimate and summarize file and directory space usage.

For those wondering, du stands for disk usage.

The typical syntax of du command is given below:

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

du [OPTION]... --files0-from=F

Now, allow me to show you how to find directory size in Linux from command line using du command with examples.

1. Display current directory size

Enter 'du' command without any options to display the size of the current directory and its sub-directories.

$ du

sample output:

Find the size of current directory in Linux
Find the size of current directory in Linux

As you see in the above output, du command displays the disk usage of my current directory along with its sub-directories.

2. Display size of a specific directory

To display a particular directory's size, for example ostechnix, run:

$ du ostechnix/

Sample output:

36252 ostechnix/Swami Vivekananda (Chicago Speech)
452 ostechnix/MultiCD/plugins
44 ostechnix/MultiCD/.git/hooks
4 ostechnix/MultiCD/.git/branches
1012 ostechnix/MultiCD/.git/objects/pack
4 ostechnix/MultiCD/.git/objects/info
1020 ostechnix/MultiCD/.git/objects
8 ostechnix/MultiCD/.git/logs/refs/heads
8 ostechnix/MultiCD/.git/logs/refs/remotes/origin
12 ostechnix/MultiCD/.git/logs/refs/remotes
24 ostechnix/MultiCD/.git/logs/refs
32 ostechnix/MultiCD/.git/logs
8 ostechnix/MultiCD/.git/refs/heads
4 ostechnix/MultiCD/.git/refs/tags
8 ostechnix/MultiCD/.git/refs/remotes/origin
12 ostechnix/MultiCD/.git/refs/remotes
28 ostechnix/MultiCD/.git/refs
8 ostechnix/MultiCD/.git/info
1168 ostechnix/MultiCD/.git
140 ostechnix/MultiCD/maps
2706504 ostechnix/MultiCD
2832056 ostechnix/

You can also display the size of multiple directories in one go like below:

$ du ~/Desktop/ ~/Downloads/

3. Display directory size in human-readable format

By default, du displays the size in bytes. We can also display the size in "human readable format" (i.e. auto-selecting the appropriate unit for each size), rather than the standard block size.

To do so, add -h tag with du command as shown below.

$ du -h ostechnix/

Sample output:

36M ostechnix/Swami Vivekananda (Chicago Speech)
452K ostechnix/MultiCD/plugins
44K ostechnix/MultiCD/.git/hooks
4.0K ostechnix/MultiCD/.git/branches
1012K ostechnix/MultiCD/.git/objects/pack
4.0K ostechnix/MultiCD/.git/objects/info
1020K ostechnix/MultiCD/.git/objects
8.0K ostechnix/MultiCD/.git/logs/refs/heads
8.0K ostechnix/MultiCD/.git/logs/refs/remotes/origin
12K ostechnix/MultiCD/.git/logs/refs/remotes
24K ostechnix/MultiCD/.git/logs/refs
32K ostechnix/MultiCD/.git/logs
8.0K ostechnix/MultiCD/.git/refs/heads
4.0K ostechnix/MultiCD/.git/refs/tags
8.0K ostechnix/MultiCD/.git/refs/remotes/origin
12K ostechnix/MultiCD/.git/refs/remotes
28K ostechnix/MultiCD/.git/refs
8.0K ostechnix/MultiCD/.git/info
1.2M ostechnix/MultiCD/.git
140K ostechnix/MultiCD/maps
2.6G ostechnix/MultiCD
2.8G ostechnix/

Now you see the size of the directories in Kilobytes, Megabytes and Gigabytes, which is very clear and easy to understand.

4. Display directory size in a specific format

We can also display the disk usage size only in KB, or MB, or GB.

To do so, use -k for kilobytes, -m for megabytes

$ du -k ostechnix/
$ du -m ostechnix/

5. Display grand total size of directories

We can display just the total human-readable size of the current working directory using -s and -h flags.

$ du -sh

Here, -s flag indicates summary.

Sample output:


If you want to check the total disk space used by a particular directory, run:

$ du -sh ~/ostechnix

We can also display the size of multiple directories at once as shown below.

$ du -sh ~/Desktop ~/Downloads

To get the grand total of the combined directories in human-readable format, for example ~/Desktop, ~/DownLoads and ~/Music, add -c flag:

$ du -chs ~/Desktop ~/Downloads ~/Music

Here, -c refers the cumulative total.

Sample output:

4.0K	/home/sk/Desktop
47G	/home/sk/Downloads
3.9G	/home/sk/Music
51G	total

To display only the grand total of the given directory including all the sub-directories, use 'grep' command with 'du' command like below.

$ du -ch Downloads/ | grep total
47G total

6. Display sizes of a directory and subdirectories, up to N levels deep

A directory may contain large number of sub-directories. You may want to list the sizes of a directory and any subdirectories, only up to N levels deep.

The following command displays the human-readable sizes of the given directory and its sub-directories, up to 2 level deep:

$ du -h --max-depth=2 ~/Downloads

Alternatively, you can use the -d flag to display results up to N levels deep.

$ du -h -d 2 Downloads/

7. Sort directories based on size

To find out which sub-directories consume how much disk size and sort them by their size, use this command:

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

The largest sub-directories will be displayed on the top. You can increase the directory depth level by increasing the value of --max-depth parameter.

8. Find the size of both files and directories

As you may noticed in the all above outputs, du command only displayed the disk usage of directories. But, what about the files? 

To display the disk usage of all items including files and directories, use -a flag.

$ du -ah ostechnix/

Now, you will see the disk usage of all files and folders in human readable format.

Sample output:

Display disk usage of files and folders in human readable format in Linux
Display disk usage of files and folders in human readable format in Linux

9. Exclude certian type of files

The following command will display the size of the current directory including its sub-directories, but it will exclude the size of all .mp4 files.

$ du -ch --exclude='*.mp4' | grep total 
6.4G total

Tip: Can we find the biggest or smallest directories/files? Of course, yes! Check the following guide.

For more details about 'du' command, check the man pages.

$ man du


In this guide, we looked at how to find the total size of directory in Linux using du command with examples. As you can see, getting folder or directory size in Linux is not a big deal.

You May Also Like


Andrea Florio January 3, 2020 - 2:47 pm

for people looking at the short answer..

du -h -d 1

sk January 3, 2020 - 6:41 pm

Brilliant. Thanks.

Bernhardt September 12, 2020 - 12:39 am

Excellent post, thank you

champi November 19, 2022 - 5:55 am

“du ostechnix/” does not display that directory’s size but the size of everything it contains.
It’s confusing if you write a description but then the examples given don’t coincide with the description.
Other than that, very good.
Thank you

1 2

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More