How to find out the size of a folder in Linux

I will give below examples of commands by which it is possible to look at the size of folders in Linux.

For example, using the du command (the size of the subfolders is displayed and the total size at the end, the sudo command is used to elevate privileges to access all folders):

du dirname
sudo du -h /home

Indicating the viewing depth, for example, if there are many subfolders in the folder:

sudo du -h --max-depth=1 /home

View only the total size of the specified folder:

sudo du -h -s /home

An example of displaying the size of folders excluding the user directory:

sudo du -h --exclude='user' /home

I will also describe du startup keys:
-a (display the size of all files, not just directories)
-h (display information in a human-readable format, Kb, Mb, not the numbers themselves)
-c (display the total size at the end, convenient if several directories are specified with a space)
-P (do not follow symbolic links (default))
–max-depth=N (display depth of subfolders)
–exclude=SAMPLE (exclude files by pattern)
–time (view the time of the last data modification)
–help (view built-in help)
–version (view du version)

Did my article help you? How about buying me a cup of coffee as an encouragement? Buy me a coffe.

Leave a comment

Leave a Reply