Google Cloud Compute Engine

How to Find Directory Size in Ubuntu 18.04 / Debian 9

Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we recommended.

Pinterest LinkedIn Tumblr

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.

This guide is tested on Google Cloud Platform and you can try this on your own Linux system or server or any VPS or Dedicated or Cloud Solutions like below.

Prepare yourself for a role working as an Information Technology Professional with Linux operating system

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.

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.

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/
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
260K html/partials

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

du -sh html /home/folder/
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/
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

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 

3.6G total

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

man du


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.