Managing Disk Space and Usage in Linux
Handling disk space is an essential duty for Linux administrators and users. When a disk becomes full, it can slow down performance, break services, and even block user access to important directories. Whether managing a personal computer, a dedicated server, or a cloud instance, knowing how to monitor disk usage ensures system reliability and prevents unexpected downtime.
This guide demonstrates how to review disk space and usage on Linux with built-in terminal tools. You will see how to detect large files, evaluate mounted file systems, and fix disk-related problems effectively.
Commands to Check Disk Space and Usage
Linux provides several command-line utilities to track and manage storage usage. These commands reveal how much space is consumed, how much remains, and which files or directories are taking the most capacity. Using them regularly helps avoid system lags, service interruptions, and data issues caused by full partitions.
Common Disk Management Commands
| Command | Description | Typical Use Case |
|---|---|---|
| df | Shows available and used disk space on mounted file systems. | View an overview of all partitions. |
| du | Summarizes space consumption by directories and files. | Identify the largest directories. |
| find | Searches files and directories based on size, type, name, or modification time. | Locate large or old files using flags like -size, -mtime, -type. |
How to Check Disk Space
The df command gives a quick snapshot of storage usage across all mounted partitions. Use it to identify low-space partitions before system performance is affected.
df Command Syntax
The general syntax is:
df [OPTION]... [FILE]...
[OPTION]: Flags passed to the command.
[FILE]: A file or directory. If not specified, all mounted file systems are displayed.
Common df Options
| Option | Description |
|---|---|
| -h, –human-readable | Display sizes in KB, MB, GB. |
| -B, –block-size=SIZE | Scale output to specified size (e.g., MB). |
| -i, –inodes | Show inode statistics. |
| -l, –local | Show only local file systems. |
| –sync | Run sync before output. |
| –total | Provide a grand total. |
| -t, –type=TYPE | Limit listing to certain file system types. |
| –help, –version | Display help or version info. |
df Command Examples
Show all mounted file systems in human-readable format:
df -h
Example output:
Filesystem Size Used Avail Use% Mounted on
/dev/vda2 150G 12G 132G 9% /
/dev/vda1 260M 7.1M 253M 3% /boot/efi
tmpfs 768M 4.0K 768M 1% /run/user/1000
/dev/vdb1 40G 1.1G 37G 3% /mnt
/dev/vdc1 40G 375M 40G 1% /home
Here you can see columns for Filesystem, Size, Used, Available, Usage %, and Mount point.
Check usage of a single mount point:
df -h /mnt
Filter by file system type (e.g., ext4):
df -h -t ext4
Exclude a specific type (e.g., tmpfs):
df -h -x tmpfs
Show output with file system types included:
df -hT
Check inode usage:
df -i
How to Check Disk Usage
The du command calculates and displays disk usage of files and directories. It’s valuable for identifying large items that may need cleanup.
du Command Syntax
du [OPTION]... [FILE]...
du Command Options
| Option | Description |
|---|---|
| -h, –human-readable | Output in KB, MB, GB. |
| -s, –summarize | Show total size only. |
| -a, –all | Include file sizes as well. |
| -c, –total | Produce a grand total. |
| -d N, –max-depth=N | Limit directory depth. |
| –exclude | Ignore specified files. |
du Command Examples
Check usage of a directory:
sudo du -sh /path/to/directory
Include hidden files:
sudo du -ah /path/to/directory
Exclude specific files:
sudo du -ah --exclude='*.log' /path/to/directory
Limit depth to top-level subdirectories:
sudo du -h --max-depth=1 /var
Sort by size:
sudo du -h --max-depth=1 /var | sort -rh
Find files larger than 50MB:
sudo find /var -type f -size +50M -exec ls -lh {} \;
Conclusion
With commands like df, du, and find, you can efficiently monitor storage, detect large files, and prevent downtime due to full disks. Applying these tools keeps your Linux systems optimized and reliable.


