Hire me on Fiverr! for Professional Google Cloud Services, WordPress Website Development, Security Setup, Website Migration.

How to Find Directory Size in Ubuntu 18.04 / Debian 9. This tutorial explains how to find the size of a directory in operating systems like Ubuntu and Debian.

Finding the size of files and directories in GUI mode is easy! But the more fastest method is using CLI (Command Line Interface). Here you are going to learn how to check file size and directory size in Linux.

Find the size of a directory

To find out the size of a directory, the du command is used. du stands for disk usage.

The syntax of du command is given below:

du [OPTION} [FILE] [directory}
du [OPTION] --files0-from=F

To display a specific directory’s size, for example html, run:

du html/

Sample Output will be similar to this.

Output
12 html/partials/blocks/templates
32 html/partials/blocks
44 html/partials/header
32 html/partials/footer
20 html/partials/home
8 html/partials/content
40 html/partials/single
260 html/partials

As you can see in the above output, the size of the directories are displayed in a non-readable format. So, you use the below command to display in more readable format.

du -h html/

Now the output will be like this.

Output
12K html/partials/blocks/templates
32K html/partials/blocks
44K html/partials/header
32K html/partials/footer
20K html/partials/home
8.0K html/partials/content
40K html/partials/single
260K html/partials

You 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 html/
du -m html/

For calculating which sub-directories consume how much disk size, you can 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.

The du command only displays the disk usage of directories. To display the disk usage of all items including files and directories, you can use -a flag.

du -ah html/
Output
4.0K html/partials/post-meta.tpl
4.0K html/partials/comment.tpl
.....

.....
4.0K html/partials/single/post-navigation.tpl
4.0K html/partials/single/post-title-meta.tpl
4.0K html/partials/single/layout-magazine.tpl
4.0K html/partials/single/related-posts.tpl
40K html/partials/single
260K html/partials

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

du -h folder1 folder2

To check the total disk space used by a particular directory, use the -s flag.

du -sh html
Output
260K html/partials

Similarly, to display the total disk space used by multiple directories, you can use this command.

du -sh html /home/folder/
Output
260K html/partials
25G /home/folder/

To display the grand total of directories, simply add the -c flag with du -sh command.

du -csh html /home/folder/
Output
260K html/partials
25G /home/folder/
25G 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 folder-name/ | grep total

Output
15G total

You can also exclude a certain 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 .mp3 files.

du -ch --exclude='*.mp3' | grep total 

Output
3.6G total

Execute the following command to know more options for the du command.

man du

Conclusion

Now you have learned how to use the du command to check the directory size and file size on your Ubuntu or Debian systems.

Thanks for your time. If you face any problem or any feedback, just leave a comment below.

1 Comment

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.