Skip to main content

Check Disk Space and Usage in Linux

This guide explains how to check disk space and storage usage on a Linux system (VPS, dedicated server, cloud instance). A full disk can degrade performance, cause services to fail, or prevent logins. Knowing how to use df, du, and find helps you monitor partitions, identify the heaviest directories and files, and avoid outages.

Prerequisites

  • SSH access to your Linux server (Debian, Ubuntu, or other distribution)
  • Administrative rights (sudo) to read all directories (some are protected)

Connect to the Server

Connect via SSH to your server:

ssh user@server_ip_address

Useful Commands for Disk Space

Linux provides command-line tools to track used storage, free space, and which files or directories use the most space.

Command Overview

CommandDescriptionTypical use
dfShows used and available space on mounted filesystemsOverview of partitions
duEstimates space used by directories and filesIdentify heaviest directories
findSearches for files by size, name, type, or dateFind large or old files

Check Disk Space with df

The df (disk free) command gives a quick view of disk space on all mounted filesystems. Use it to spot partitions that are filling up.

Syntax of df

df [OPTION]... [FILE]...
  • OPTION: command options (human-readable format, filesystem type, inodes, etc.)
  • FILE: optional file or directory. If omitted, df shows all mounted filesystems.

Common df Options

OptionDescription
-h, --human-readableShow sizes in human-readable units (K, M, G)
-B, --block-size=SIZEUse given block size (e.g. -BM for megabytes)
-i, --inodesShow inode usage instead of blocks
-l, --localLimit output to local filesystems
--totalShow a total line
-t, --type=TYPELimit to a filesystem type (e.g. ext4, xfs)
-x, --exclude-type=TYPEExclude a filesystem type (e.g. tmpfs)
-TShow filesystem type in a column

Examples: df Command

Show disk space for all filesystems (human-readable):

df -h

Example output:

Filesystem      Size  Used Avail Use% Mounted on
...
/dev/sda2 150G 12G 132G 9% /
/dev/sda1 260M 7.1M 253M 3% /boot/efi
tmpfs 768M 4.0K 768M 1% /run/user/1000
/dev/sdb1 40G 1.1G 37G 3% /mnt

Useful columns:

  • Filesystem: device or filesystem name
  • Size: total partition size
  • Used: space in use
  • Avail: free space
  • Use%: usage percentage
  • Mounted on: mount point

Check space for a specific mount point (e.g. /mnt):

df -h /mnt

Show only a given filesystem type (e.g. ext4):

df -h -t ext4

Exclude a filesystem type (e.g. tmpfs):

df -h -x tmpfs

Show filesystem type:

df -hT

Show inode usage:

Inodes store metadata for files and directories. If the disk has free space but inodes are exhausted, you cannot create new files.

df -i

Example output:

Filesystem     Inodes  IUsed   IFree IUse% Mounted on
...
/dev/sda2 41611680 123735 41487945 1% /
/dev/sdb1 2621440 12 2621428 1% /mnt
  • Inodes: total inodes
  • IUsed: inodes in use
  • IFree: free inodes
  • IUse%: inode usage percentage

Check Disk Usage with du

The du (disk usage) command estimates space used by directories and files. Use it to see which directories or files use the most space.

Syntax of du

du [OPTION]... [FILE]...
  • OPTION: command options
  • FILE: directory or file to analyze. If omitted, du starts from the current directory.

Common du Options

OptionDescription
-h, --human-readableSizes in human-readable units (K, M, G)
-s, --summarizeShow only total for the given directory
-a, --allInclude all files, not just directories
-c, --totalShow a grand total at the end
-d N, --max-depth=NLimit traversal depth to N levels
--exclude=PATTERNExclude files/directories matching pattern

Examples: du Command

Total size of a directory (human-readable):

sudo du -sh /path/to/directory

Using sudo is recommended to access all directories (some are protected).

Include all files (including hidden):

sudo du -ah /path/to/directory

Exclude certain file types (e.g. .log files):

sudo du -ah --exclude='*.log' /path/to/directory

Size of first-level subdirectories (e.g. /var):

sudo du -h --max-depth=1 /var

Example output:

22M     /var/log
97M /var/lib
4.0K /var/yp
216M /var

Sort subdirectories from largest to smallest:

sudo du -h --max-depth=1 /var | sort -rh

Example output:

216M    /var
97M /var/lib
97M /var/cache
22M /var/log
...

Find Large Files with find

The find command searches for files by size, name, type, or date. Combined with du, it helps locate the largest files.

List files larger than 50 MB in a directory (e.g. /var):

sudo find /var -type f -size +50M -exec ls -lh {} \;

Example output:

-rw-r--r-- 1 root root 65M May  6 20:29 /var/lib/rpm/rpmdb.sqlite

Search for files larger than 100 MB system-wide:

sudo find / -type f -size +100M 2>/dev/null
2>/dev/null

The redirect 2>/dev/null hides permission denied errors to keep output readable.

Find files modified more than 30 days ago (for cleanup):

sudo find /var/log -type f -mtime +30

Command Summary

GoalCommand
Partition overviewdf -h
Space for a mount pointdf -h /mnt
Inode usagedf -i
Directory sizesudo du -sh /path
Subdirectories sorted by sizesudo du -h --max-depth=1 /var | sort -rh
Files larger than 50 MBsudo find /var -type f -size +50M -exec ls -lh {} \;

Troubleshooting

Full or nearly full partition

  • Use du to find the heaviest directories (often /var, /tmp, /home, logs).
  • Clean old logs: sudo journalctl --vacuum-time=7d or remove files in /var/log.
  • Clear package caches: sudo apt clean (Debian/Ubuntu) or equivalent.
  • Remove temporary files in /tmp if needed.

"No space left on device" but space appears free

  • Check inodes: df -i. If IUse% is 100%, the disk has no inodes left (many small files). Remove or move files to free inodes.

Commands fail due to permissions

  • Use sudo for du and find on system directories (/var, /etc, /root, etc.).

References

  • Man pages: man df, man du, man find