KIM COMPUTER


du (Disk Usage)

The du command is used to estimate file space usage. It tracks the space utilized by each file and directory, making it an essential tool for identifying storage hogs and managing disk space effectively.


1. Basic Usage

du [options] [directory/file]

2. Key Options

Option Name Description
-h human-readable Displays sizes in KB, MB, or GB for easy reading.
-s summarize Shows only a total for each specified argument.
-a all Shows counts for all files, not just directories.
-d N max-depth Limits the display to N levels deep into the directory tree.
-c total Produces a grand total at the bottom of the output.

3. Practical Examples

① Checking the total size of the current folder

du -sh .

② Checking sizes of subdirectories at a specific depth

du -h -d 1 /home/user/

③ Finding the top 10 largest directories

du -ah /var | sort -rh | head -n 10

4. [Tip] Why the numbers might differ

Sometimes du shows a different value than ls -l. This is because du reports the actual disk blocks consumed, which includes file system overhead, while ls reports the apparent size of the file content.