Checking Disk Space and Disk Usage
Learn how to use df and du to check filesystem capacity, measure directory usage, find large files, and investigate full-disk conditions from the command line.
When a system reports that a download, save, or installation failed because there is no space, two related questions matter: How much space is available on the filesystem? and Which files or directories are consuming it? Linux and Unix-like systems commonly answer these questions with df and du.
Disk Space Versus Disk Usage
Disk space is storage capacity on a filesystem. A filesystem is a formatted storage structure that organizes files and directories. Its capacity is the total amount of storage it can provide.
Disk usage is the amount of storage consumed by files and directories. If a filesystem has a capacity of 100 GB and files consume 65 GB, about 35 GB remains available, subject to filesystem overhead and reserved space.
- Capacity: the total size of the filesystem.
- Used: storage currently occupied or reserved for filesystem data.
- Available: storage that ordinary users or processes can still allocate.
A directory or file has a size, but it does not have the same meaning as filesystem capacity. For example, /home/alex/project might contain 4 GB of files, while the filesystem mounted at /home might have a capacity of 500 GB. The directory is only one consumer of that filesystem.
Storage usage is also different from memory usage. Disk space describes persistent storage such as an SSD or hard disk. Memory usage describes RAM used by running programs and the operating system. Commands such as df and du inspect storage, not RAM.
Viewing Filesystem Free Space with df
The df command reports space at the filesystem level. Run it without a path to inspect mounted filesystems visible to the system:
df
For easier reading, add -h. This requests human-readable output, using units such as K, M, G, or T:
df -h
A typical report resembles this:
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 100G 65G 30G 69% /
/dev/sda3 500G 120G 355G 26% /home
| Column | Meaning | Example interpretation |
|---|---|---|
| Filesystem | The device or logical storage source providing the filesystem. | /dev/sda2 is the source for the root filesystem in the example. |
| Size | Total filesystem capacity. | The filesystem has a capacity of 100 GB. |
| Used | Space consumed or reserved for filesystem data. | 65 GB is currently used. |
| Available | Space that can still be allocated to ordinary users or processes. | About 30 GB can still be used. |
| Use% | The percentage of the filesystem reported as used. | 69% indicates that the filesystem is more than two-thirds full. |
| Mounted on | The directory through which the filesystem is accessed; this is its mount point. | / is the root mount point and /home is a separate mount point. |
Checking the Filesystem for a Specific Path
Give df a path when you need to know which filesystem contains that location:
df -h /home
This is especially useful when investigating a particular directory. The command reports the filesystem containing /home, not the total size of files inside that directory. You can also check a project or download location:
df -h ~/project
df -h /var/log
Measuring Directory and File Usage with du
The du command estimates the storage used by files and directories. Unlike df, which asks how full a filesystem is, du examines directory contents.
du
With a directory argument, du normally walks the directory tree and reports usage for directories it visits. This recursive listing can contain many lines. Add -h for readable units:
du -h ~/project
Use -s to summarize the directory instead of displaying a separate result for each directory in the tree:
du -s ~/project
The most convenient form for a concise, readable total is du -sh:
du -sh ~/project
For example, output such as 4.2G /home/alex/project means that the files found under that directory account for approximately 4.2 GB according to du.
| Command | Measures | Best used for | Typical scope |
|---|---|---|---|
df | Filesystem-level capacity, used space, and available space. | Determining whether a mounted filesystem is full. | An entire mounted filesystem or the filesystem containing a supplied path. |
du | Estimated space consumed by files and directories. | Finding which directories or files use storage. | A supplied directory tree or file. |
Finding Large Storage Consumers
Once df -h identifies a nearly full mount point, compare its immediate child directories. On systems with GNU du, use --max-depth=1 to report the target directory and its direct children:
du -h --max-depth=1 .
Sort the readable output by size to make the largest entries easier to spot:
du -h --max-depth=1 . | sort -h
Run the command from the directory you want to examine, or provide an explicit path:
du -h --max-depth=1 /var | sort -h
du -h --max-depth=1 /home | sort -h
The final entries in ascending output are usually the largest. If your system does not support GNU du, consult that system's du manual for its depth option; option names differ among Unix implementations.
After locating a large directory, repeat the comparison inside it. To locate individual large files, use find with a size threshold:
find ~/project -type f -size +500M -print
This lists regular files larger than 500 MB beneath ~/project. A large file is not automatically safe to remove. It might be an active database, a required application file, a useful backup, or a log needed for troubleshooting.
Filesystem Mounts and Paths
A mount point is the directory through which a filesystem is accessed. Different directories can be backed by different mounted filesystems. For example:
/ mounted filesystem A
└── home mounted filesystem B
└── alex files on filesystem B
In this arrangement, / and /home have independent capacities. Therefore these commands can show different results:
df -h /
df -h /home
The root filesystem can be nearly full while the filesystem mounted at /home still has plenty of available space. Conversely, a large home directory might fill /home without consuming the free capacity reported for another filesystem.
Use the Mounted on column in df -h to connect a path with its filesystem. When measuring directories with du, remember that the directory tree may include mounted subdirectories. If you need to keep an investigation within one filesystem and your implementation supports it, check the du manual for an option such as -x or --one-file-system.
Interpreting Full-Disk Conditions
High Utilization or Zero Available Space
A filesystem is in immediate danger of failure when df -h shows a very high Use% value or an Avail value of zero. Programs may be unable to create files, extend logs, download data, or complete updates.
A small directory does not prove that its filesystem has free space. Other directories sharing the same mount may contain the storage consumers. Always identify the affected mount point first.
Inode Exhaustion
An inode is filesystem metadata used to track a file. A filesystem can run out of inodes after storing a very large number of small files, even when ordinary data space remains.
df -ih
This displays inode capacity and usage in a readable form. If inode availability is zero or nearly zero, investigate directories containing huge numbers of small files. Permission restrictions, storage quotas, or other limits can also prevent file creation, so inode exhaustion is one possible diagnosis rather than the only one.
Safe Disk-Space Investigation Workflow
- Check filesystem capacity first. Run
df -hto see which mounted filesystem is full or nearly full. - Identify the affected mount point. Run
df -h /path/to/locationfor the directory where the failure occurred. - Measure likely directories. Use
du -shon directories associated with projects, downloads, temporary data, builds, logs, or user files. - Compare immediate children. Use a depth-limited
dureport andsort -hto find the largest branches. - Locate unusually large files. Use
findwith an appropriate size threshold. - Review before changing anything. Confirm what each file does and whether it is active before cleaning, archiving, moving, or removing it.
- Check inodes when necessary. If
dfshows available storage but file creation fails, rundf -ihand investigate permissions or quotas as well.
Troubleshooting Examples
A Save or Download Fails with a No-Space Error
- Run
df -hand look for a filesystem with very high usage. - Run
df -hagainst the target directory to verify its mount point. - Use
du -shand immediate-subdirectory comparisons within that filesystem. - Review large temporary, download, build, log, or user files before deciding what action is safe.
df Shows Free Space but Creating a File Fails
Run df -ih. A very large number of small files may have consumed all inodes. If inode capacity is also available, investigate permissions, quotas, and application-specific limits.
The Root Filesystem Is Full but Home Has Room
Compare df -h / with df -h /home. If they report different filesystems, /home is a separate mount and its free space cannot directly satisfy writes to the root filesystem.
du Reports Less Usage Than df
df and du measure different things and may inspect different scopes. Verify that du covered the relevant directories and filesystem. Also consider files deleted from the directory tree but still held open by running processes, filesystem metadata, snapshots, reserved blocks, and mount boundaries. These can make filesystem-level usage exceed the visible directory totals.
Command Reference
| Task | Command | What to inspect |
|---|---|---|
| Check filesystem capacity | df -h | Capacity, used space, available space, percentage, and mount points for mounted filesystems. |
| Check a path's filesystem | df -h /path/to/location | The filesystem that contains the specified path. |
| Summarize a directory | du -sh /path/to/directory | One readable total for the directory tree. |
| Compare subdirectories | du -h --max-depth=1 /path/to/directory | sort -h | Relative sizes of immediate children; this uses GNU du syntax. |
| Check inode usage | df -ih | Inode capacity, used inodes, available inodes, and inode percentage. |
For related command-line practice, see Essential Linux Commands and Useful Terminal Commands.