Linux Useful

du – Get the Size of a Folder in Ubuntu Linux

The linux du command displays the size of file space used by the specified files or folders. If the specified path is a directory (folder), du summarizes disk usage of each subdirectory in that directory. Otherwise, du reports the disk usage of the current working folder.

To get the total size of the /srv folder, use following linux command:
[email protected]:/home# sudo du -sh /var
[email protected]:/srv/SAMSUNG-850-PRO/MOST-RECENT# sudo du -shc /srv
15T /srv/
15T total

where arguments is:

  • s – Display only the total size of the specified folder, do not display file size totals for subfolders.
  • h – Print in a human-readable format (kb, mb, gb, tb)
to get a report about the disk usage of the 1st-level subfolders is to use the –max-depth option:
sudo du -h --max-depth=1 /srv
2.2T /srv/SEAGATE3-8T
12K /srv/ftp
6.1T /srv/SAMSUNG-8T
5.8T /srv/SEAGATE2-8T
172G /srv/SAMSUNG-850-PRO
4.0K /srv/HGST-4T
15T /srv
to print sorted, only the top 10 folders:
[email protected]:/# du -h /usr/ | sort -rh | head -10
4.1G /usr/
3.0G /usr/lib
1.1G /usr/lib/x86_64-linux-gnu
656M /usr/lib/modules
582M /usr/lib/firmware
347M /usr/share
320M /usr/lib/modules/5.4.0-90-generic
320M /usr/lib/modules/5.4.0-89-generic
311M /usr/src
272M /usr/lib/modules/5.4.0-90-generic/kernel

Leave a Reply

Your email address will not be published. Required fields are marked *