Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

Linux & Mac & Bash Command Dictionary

  1. Home
  2. Linux & Mac & Bash Command Dictionary
  3. df / du

df / du

df and du are the essential Linux commands for checking disk free space and per-directory usage. Use df -h to get a human-readable overview of all filesystems, and du -sh /* to identify which directories are consuming the most space. The interactive TUI tool ncdu lets you drill down visually as you investigate.

Syntax

# -----------------------------------------------
#  df (Disk Free) — Check free space across all filesystems
# -----------------------------------------------

# df -h
#   → Shows disk usage for all mount points in human-readable units
#   → Sizes are displayed in GB, MB, etc.
#   Example: df -h

# df -i
#   → Shows inode usage instead of block usage
#   → When inodes are exhausted, no new files can be created
#   Example: df -i

# df -h {mount_point}
#   → Shows only the specified mount point
#   Example: df -h /var

# -----------------------------------------------
#  du (Disk Usage) — Check usage by directory
# -----------------------------------------------

# du -sh {directory}
#   → Shows the total size of the specified directory in human-readable units
#   → -s: summary only (does not expand subdirectories)
#   → -h: human-readable units (K/M/G)
#   Example: du -sh /var/log

# du -h --max-depth=1 {directory}
#   → Shows the size of each immediate subdirectory under the given path
#   → --max-depth=1: expands only one level deep
#   Example: du -h --max-depth=1 /var

# du -hs * | sort -rh
#   → Lists all entries in the current directory sorted by size, largest first
#   → sort -r: reverse order (largest first)  sort -h: correctly compares human-readable sizes
#   Example: cd /var && du -hs * | sort -rh

# -----------------------------------------------
#  ncdu — Interactive TUI disk investigation tool
# -----------------------------------------------

# ncdu {directory}
#   → Displays a directory tree in TUI and lets you drill down with the keyboard
#   → Install: sudo apt install ncdu (Debian/Ubuntu)
#   →          sudo dnf install ncdu (RHEL/AlmaLinux)
#   Example: ncdu /

# -----------------------------------------------
#  find — Detect large files
# -----------------------------------------------

# find {directory} -size +{size} -type f
#   → Lists files exceeding the specified size
#   → +100M: over 100 MB  +1G: over 1 GB
#   Example: find / -size +100M -type f 2>/dev/null

Command Reference

CommandDescription
df -hShows free space for all mount points in human-readable units (K/M/G). Any mount point where Use% exceeds 90% warrants attention.
df -iShows inode usage. When a filesystem holds an enormous number of files, inodes can run out even when block space is still available, preventing new files from being created.
df -h /varShows free space for a specific mount point only.
du -sh {directory}Displays the total size of the specified directory in a single line. Useful for a quick size estimate.
du -h --max-depth=1 {directory}Expands one level of subdirectories under the given path and shows their sizes. Useful for identifying which subdirectory is taking up the most space.
du -hs * | sort -rhLists entries in the current directory sorted by size, largest first. Lets you quickly spot the largest directories.
ncdu {directory}Displays a directory tree in TUI and lets you drill down with the arrow keys. You can also delete files with the d key.
find / -size +100M -type f 2>/dev/nullSearches for files larger than 100 MB. Useful for finding old backups or bloated log files.
find / -name "*.log" -size +50M 2>/dev/nullSearches for log files larger than 50 MB. Helpful for finding logs that have grown out of control due to a missing logrotate configuration.

Examples

Investigating the cause of a full disk
# -----------------------------------------------
#  Steps to diagnose disk exhaustion
#  (when / reaches 98% on Kiryu Kazuma's server)
# -----------------------------------------------

# Step 1: Check which mount point is running low
df -h

# Step 2: Find which top-level directory is using the most space
du -h --max-depth=1 /

# Step 3: If /var looks large, drill down further
du -h --max-depth=1 /var

# Step 4: If /var/log looks suspicious, inspect the log directory
du -hs /var/log/* | sort -rh

# Step 5: List files over 100 MB to find clues
find /var -size +100M -type f 2>/dev/null

# Step 6: Use ncdu to visually browse and delete unnecessary files
# (move with j/k or arrow keys, delete with d)
ncdu /var

Run the following command:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   48G  980M  98% /
/dev/sda2       100G   12G   88G  12% /home
tmpfs           7.8G     0  7.8G   0% /dev/shm
$ du -h --max-depth=1 /var
4.0K	/var/backups
2.1G	/var/log
890M	/var/lib
44G	/var/lib/kiryu_db_backup
4.0K	/var/cache
46G	/var
$ find /var -size +100M -type f 2>/dev/null
/var/lib/kiryu_db_backup/dump_20260101.sql.gz
/var/lib/kiryu_db_backup/dump_20260201.sql.gz
/var/lib/kiryu_db_backup/dump_20260301.sql.gz
/var/log/nginx/majima_access.log.1
Diagnosing inode exhaustion
# -----------------------------------------------
#  Check whether inodes are exhausted
#  (when Majima Goro's server shows "No space left on device"
#   but df -h shows plenty of free space)
# -----------------------------------------------

# Check inode usage
# IUse% close to 100% indicates inode exhaustion
df -i

# Find directories consuming the most inodes
# (identifies directories with a very large number of files)
find / -xdev -printf '%h\n' 2>/dev/null | sort | uniq -c | sort -rn | head -20

Run the following command:

$ df -i
Filesystem      Inodes  IUsed   IFree IUse% Mounted on
/dev/sda1      3276800 3276795       5  100% /
/dev/sda2      6553600  124032 6429568    2% /home
$ find / -xdev -printf '%h\n' 2>/dev/null | sort | uniq -c | sort -rn | head -5
 892341 /var/spool/majima_mail_queue
  84210 /tmp/nishiki_sessions
   4821 /var/log
    312 /usr/lib
    201 /etc
Investigating interactively with ncdu
# -----------------------------------------------
#  Installing and using ncdu
# -----------------------------------------------

# Install on Debian/Ubuntu
sudo apt install ncdu

# Install on RHEL/AlmaLinux
sudo dnf install ncdu

# Start scanning from / (may take a while)
ncdu /

# Scan only /home for a quicker investigation
ncdu /home

# Save the scan result to a file for later review
# (useful when you want to minimize load on a production server)
ncdu -o /tmp/tatsuya_disk_report.json /
ncdu -f /tmp/tatsuya_disk_report.json

Run the following command:

$ ncdu /home
ncdu 1.19 ~ Use the arrow keys to navigate, press ? for help
--- /home -----------------------------------------------------------------------
   18.2 GiB [##########] /kiryu
    8.7 GiB [####      ] /majima
    3.1 GiB [#         ] /nishiki
  512.0 MiB [          ] /date_true
   48.3 MiB [          ] /shinada_work
(↓ to move, → or Enter to drill down, d to delete)

Overview

df and du are the essential first tools for troubleshooting disk space issues. The standard investigation flow is: use df -h to get a bird's-eye view of all filesystems and identify mount points with a high Use%, then drill down with du -h --max-depth=1 to narrow down the cause. If you get "No space left on device" even though block space looks fine, check df -i for inode exhaustion — mail queues and temporary files can accumulate in huge numbers, draining inodes before disk blocks run out. For tracking down large files, find -size is effective at quickly surfacing old backups or bloated, unrotated logs. To prevent log bloat at the root level, review your logrotate configuration. Having a solid understanding of the Linux directory structure (FHS) also helps you decide which directories to prioritize when interpreting du results.

If you find any errors or copyright issues, please .