Find the total size of a directory from the command line in Ubuntu

In Ubuntu you can easily view the total size of a directory or folder from the terminal command line tool. And the good part is you don’t need any fancy GUI apps for this. You can view this via the du command. du is the short form of disk usage. In this article we will see how to find the size of a particular folder and all folders on your system from your terminal application.

 

Du Command in Linux:

Find a particular Folder size in terminal:

The basic syntax is

du -hs /folderpath

-h : numbers in human readable.
-s : summary only.
-c : total
-h : human-numeric-sort
-r : reverse

Example:

du -hs /home/manikandan/Downloads

Here manikandan is my username you can change with your ubuntu username. It will give the size details about the Downloads folder.

Also Read:  ArdorQuery API Testing App

If you want to get the size of the folder and all the other things inside of that folder separately, then use this command.

du -h /home/manikandan/Downloads

You can also sort by size using sort option.

du -sch /home/manikandan/Downloads/* | sort -rh

View all Folders and files size:

If you want to view the size of all folders and files in your complete system then run this command.
Note: It will scan and shows all files and folders from your system and take some time to complete.

du

Some other useful du Command Examples:

sudo du -h --max-depth=1 /var/lib
sudo du -sh --apparent-size /var/lib

If you liked this article, please subscribe to our YouTube Channel. You can also stay connected with us on X (Twitter) and Facebook.



Leave a Reply