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.
Supercharge your Linux Administration Career with completed training course and get your dream job
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
Sample Output will be similar to this.
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.
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
du command only displays the disk usage of directories. To display the disk usage of all items including files and directories, you can use
du -ah html/
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
du -sh html
Similarly, to display the total disk space used by multiple directories, you can use this command.
du -sh html /home/folder/
To display the grand total of directories, simply add the
-c flag with
du -csh html /home/folder/
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
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
du -ch --exclude='*.mp3' | grep total
Execute the following command to know more options for the
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.