Linux : Check disk usage

Posted by cikul | Posted in Linux | Posted on 23-05-2012-05-2008

0

The easiest way to check disk usage is using du command :

cikul@cikul.or.id [~]# du -sh
9.8G .

How is you want to check detailed disk usage for each folder :

cikul@cikul.or.id [~/public_html/backup]# du -Sh
68K ./images
20K ./library/js
20K ./library/admin
4.0K ./library
140K .

example case :

We have problem with /var partition that reach 89% full, to know what is using high disk usage, we can run this command :

# du -ax --max-depth 1 /var | sort -n | tail
1400 /var/tmp
12672 /var/named
29948 /var/lve
48156 /var/spool
289896 /var/cache
346028 /var/log
1477776 /var/softaculous
2550396 /var/cpanel
6554920 /var/lib
11312040 /var

from the result we can check inside the folder :

# du -ax --max-depth 1 /var/lib | sort -n | tail
16 /var/lib/stateless
28 /var/lib/iscsi
48 /var/lib/sepolgen
56 /var/lib/nfs
1480 /var/lib/spamassassin
9472 /var/lib/munin
36172 /var/lib/rpm
91608 /var/lib/mlocate
6415964 /var/lib/mysql
6554992 /var/lib

To show the disk usage in a human-readable format then you may also try the following examples (that will report files with sizes in Megabytes or Gigabytes, excluding files with sizes in Kilobytes):

# du -ahx --max-depth 1 /var | sort -k2 | egrep "[0-9](M|G)"
11G /var
284M /var/cache
2.5G /var/cpanel
6.3G /var/lib
338M /var/log
30M /var/lve
13M /var/named
1.5G /var/softaculous
48M /var/spool
1.4M /var/tmp

Using the disk usage information obtained you may consider whether or not to remove certain files; extreme caution should be practiced to ensure that required files are retained and not inadvertently deleted.

Write a comment

*