Skip to content

du

Size of files by pattern

find /path/to/dir -type f -name '*.png' -exec du -cb {} + | grep total$ | cut -f1 | paste -sd+ - | bc

Size of one folder in bytes

du -B1 -d 0 /path/to/dir

Folders size to first level with human size

du -d 1 -h /path/to/dir

du -sh /path/to/dir/*

# ... CentOS 6.7
du --max-depth=1 -h /path/to/dir

du -shx vs df -h | process holding an unlinked file

Example:

du -shx /var
32G /var

df -h |grep var
/dev/vda3        64G   55G  6.4G  90% /var

To find process holding an unlinked file:

# lsof -a +L1 {mount-point}
lsof -a +L1 /dev/vda3

COMMAND       PID    USER   FD   TYPE DEVICE    SIZE/OFF NLINK    NODE NAME
dbus-daem    2692    dbus    5r   REG  253,3    10406312     0 1966985 /var/lib/sss/mc/initgroups (deleted)
sssd_be      2874    root   20r   REG  253,3    10406312     0 1966985 /var/lib/sss/mc/initgroups (deleted)
zabbix_ag    4241  zabbix    1w   REG  253,3      662886     0  917588 /var/log/zabbix/zabbix_agentd.log-20151124 (deleted)
zabbix_ag    4241  zabbix    2w   REG  253,3      662886     0  917588 /var/log/zabbix/zabbix_agentd.log-20151124 (deleted)
bareos-fd    5215    root    9r   REG  253,3 24390987571     0  936323 /var/log/messages (deleted)