Table of Contents

Linux - du (Disk Usage)

About

du is a disk usage tool that estimates file space usage by subfolder.

It exists also as Technet edition

See also Linux - disk free command (df)

Syntax

du [OPTION]... [FILE]...
du [OPTION]... --files0-from=F

Options

Data Filtering

Summarize

Calculation

Formatting

Time
Newline
Size

Difference between du and df

du shows the space by file whereas df shows the space by block of file.

If there is a big difference in their output, try to see if some deleted file are not held by a process as open.

Example with linux and lsof

 lsof /device | grep -i deleted

Deleted Open File

If this is the case, you need to restart the process to reclaim this buffers.

Snippet

Top space

To find the top space users in a directory

du -k | sort -n

Show larger than specified size

du -h -t 100M -a

get sizes of each file

du -a tmp
4       tmp/testFile.txt
8       tmp

get total size of a folder

du --max-depth=0 ~
6167480 /home/oracle

du -s ~
6167480 /home/oracle

get size of each sub folder

du -h --max-depth=1

get sub-folder total size of containing files only (without sub-folder size)

$ du -Sc --max-depth=1 ~
8       /home/oracle/jos
20      /home/oracle/.ssh
20      /home/oracle/index_advisor
4       /home/oracle/.mozilla
345688  /home/oracle/112272_diag
36276   /home/oracle/.dropbox-dist
4       /home/oracle/.gconf
4       /home/oracle/.gnome
4       /home/oracle/.dbus
20      /home/oracle/.dropbox
4       /home/oracle/.gnome2
4       /home/oracle/.gnome2_private
4       /home/oracle/.java
20      /home/oracle/.vnc
400     /home/oracle/linux8664
8       /home/oracle/bea
8       /home/oracle/.gconfd
12      /home/oracle/oraInventory
173020  /home/oracle/crash
16      /home/oracle/.dropbox-master
256     /home/oracle/Dropbox
4       /home/oracle/.config
4       /home/oracle/oradiag_oracle
4842736 /home/oracle
6167480 total