3 Easy Ways To Get A Summary Of Disk Usage (Directory & Folders Size) In Linux

I got a mail from one of our reader two days back and he asked me, how to get the summarized size of the folder in Linux.

I know this can be achieved by Disk Usage (DU) command, even i didn’t figure out in my first attempt. So, i have used possible option combination by digging du command man page and finally got three best results.

Whenever Linux administrators saw such kind of question, instantly they might think two famous disk usage commands like DU (Disk Usage) and DF (Disk Filesystem).

Suggested Read : du (Disk Usage) Command To Check Disk Usage Of Files and Directories/Folders In Linux

By default du command shows size of current directory files and it wont shows directory and it’s sub-directory size.

Dig an article to quickly summarize size of the each directory and their sub-directory.

Method-1 : Disk Usage (DU) Command

As i told in the beginning of article, we are going to use Disk Usage (DU) command with two more options. So, use the following disk usage command combination to get the summarized sizes of the folders and their sub folders.

To use following command, make sure you should be in corresponding directory where you want to summarize directory size and fire the below command.

# du -hsc ./*
4.0K	./click.ubuntu.com
2.4G	./dump.tar.gz
70M	./emerald-icon-theme
27M	./Flat-Remix
916K	./ktube-media-downloader
380K	./ktube-media-downloader_1.0_amd64.deb
12M	./lnav
2.3M	./lnav_0.8.1_amd64.deb
204K	./ps_mem.py
50M	./Rambox-0.4.5-x64.AppImage
8.0K	./skypeforlinux
44K	./speedtest.py
21M	./sublime_text
145M	./teamviewer
12K	./uber-cli.txt
171M	./vivaldi
46M	./vivaldi-stable_1.7.735.46-1_amd64.deb
157M	./wire-desktop
3.1G	total

The above command combination will print files size and each directory actual size (Including their sub-directory) and also total size.

Details :
du : Disk Usage
h : Print sizes in human readable format
s : Display only a total for each argument
c : Produce a grand total

Alternatively use the following command to view summarized size of the folders, this will allow users to mention destination directory instead of navigating to location.

$ du -hsc /opt/*
4.0K	/opt/click.ubuntu.com
2.4G	/opt/dump.tar.gz
70M	/opt/emerald-icon-theme
27M	/opt/Flat-Remix
49M	/opt/ktube-media-downloader
380K	/opt/ktube-media-downloader_1.0_amd64.deb
12M	/opt/lnav
2.3M	/opt/lnav_0.8.1_amd64.deb
204K	/opt/ps_mem.py
50M	/opt/Rambox-0.4.5-x64.AppImage
8.0K	/opt/skypeforlinux
44K	/opt/speedtest.py
21M	/opt/sublime_text
145M	/opt/teamviewer
12K	/opt/uber-cli.txt
171M	/opt/vivaldi
46M	/opt/vivaldi-stable_1.7.735.46-1_amd64.deb
157M	/opt/wire-desktop
3.1G	total

Use one more combination to get a summary of disk usage (Directory & Folders Size) in Linux.

$ du -ah --max-depth=1
2.3M	./lnav_0.8.1_amd64.deb
204K	./ps_mem.py
12M	./lnav
27M	./Flat-Remix
44K	./speedtest.py
8.0K	./skypeforlinux
2.4G	./dump.tar.gz
157M	./wire-desktop
21M	./sublime_text
50M	./Rambox-0.4.5-x64.AppImage
145M	./teamviewer
70M	./emerald-icon-theme
49M	./ktube-media-downloader
380K	./ktube-media-downloader_1.0_amd64.deb
4.0K	./click.ubuntu.com
12K	./uber-cli.txt
171M	./vivaldi
46M	./vivaldi-stable_1.7.735.46-1_amd64.deb
3.1G	.

To View only grand total size, use the following commands.

$ du -h --max-depth=0
3.1G	.


$ du -sh /opt
3.1G	/opt

Method-2 : ncdu (NCurses Disk Usage) Command

ncdu (NCurses Disk Usage) is a curses-based version of the well-known ‘du’, and provides a fast way to see what directories are using your disk space.

$ ncdu
ncdu 1.11 ~ Use the arrow keys to navigate, press ? for help                    
--- /opt -----------------------------------------------------------------------
    2.4 GiB [##########]  dump.tar.gz                                           
  170.2 MiB [          ] /vivaldi
  156.5 MiB [          ] /wire-desktop
  144.3 MiB [          ] /teamviewer
   69.5 MiB [          ] /emerald-icon-theme
   49.3 MiB [          ]  Rambox-0.4.5-x64.AppImage
   48.5 MiB [          ] /ktube-media-downloader
   45.4 MiB [          ]  vivaldi-stable_1.7.735.46-1_amd64.deb
   26.1 MiB [          ] /Flat-Remix
   20.4 MiB [          ] /sublime_text
   11.8 MiB [          ] /lnav
    2.2 MiB [          ]  lnav_0.8.1_amd64.deb
  380.0 KiB [          ]  ktube-media-downloader_1.0_amd64.deb
  204.0 KiB [          ]  ps_mem.py
   44.0 KiB [          ]  speedtest.py
   12.0 KiB [          ]  uber-cli.txt
    8.0 KiB [          ] /skypeforlinux
e   4.0 KiB [          ] /click.ubuntu.com

 Total disk usage:   3.1 GiB  Apparent size:   3.1 GiB  Items: 23145

ncdu command will scan the current directory and show you files and folder size recursively.

Method-3 : tree Command

Tree is a recursive directory listing program that produces a depth indented listing of files and directories in a tree-like format.

$ tree --du -h /opt/ktube-media-downloader
├── [830K]  ktube-media-downloader
├── [ 246]  ktube-media-downloader.desktop
├── [2.2M]  lnav_0.8.1_amd64.deb
└── [ 45M]  WgetInterface
    ├── [ 71K]  libwgetinterface.a
    └── [ 45M]  vivaldi-stable_1.7.735.46-1_amd64.deb

  49M used in 1 directory, 5 files

The above two commands shows directory summary size but tree command will tell you an each file size inside the directory and their sub-director, also print summarized size of the directory.

Magesh Maruthamuthu

Love to play with all Linux distribution

You may also like...

Please support the site
By clicking any of these buttons you help our site to get better