Checking disk usage in Linux is often done using the df
and du
commands, which provide details on how much space is being used and where. Here’s how to use each command effectively.
Checking Disk Usage with df
#
The df
command (Disk Free) is a quick way to view available and used disk space on all mounted filesystems. By default, it shows data in 1K blocks, but you can modify it to display more user-friendly formats.
Basic Syntax #
df [options] [file]
Commonly Used Options
Below are the most commonly used options with the df command
- Display in Human-Readable Format:
- This will show the disk usage in MB, GB, etc., making it easier to interpret.
df -h

- Check a Specific Filesystem:
- Replace
/path/to/directory
with a directory or device to view its usage specifically.
- Replace
df -h /path/to/directory

- Include File System Types:
- Adds the file system type (e.g., ext4, tmpfs) in the output for each partition.
df -T

- View Inodes Usage:
- Displays the number of inodes (used/available) on each filesystem, helpful for diagnosing inode exhaustion.
df -i

Checking Disk Usage with du
#
The du
command (Disk Usage) is used to estimate the disk space used by specific files or directories. It’s more detailed than df
, allowing you to view usage down to the folder level.
Basic Syntax
#
du [options] [directory]
Commonly Used Options
Below are the most commonly used options with the du command.
- Display in Human-Readable Format:
- This will show folder sizes in KB, MB, GB, etc for the working directory.
du -h

- Summarize Directory Usage:
- The
-s
option gives the total size of the specified directory without listing sub-directories.
- The
du -sh /path/to/directory

- List Directory and Subdirectory Usage:
- Shows the disk usage of each directory and sub-directory.
du -h /path/to/directory/*

- Limit Depth:
- Limits the depth of directories shown to the specified level, providing an overview of immediate sub-directory sizes.
du -h --max-depth=1 /path/to/directory

Summary #
- Use
df
for a broad overview of disk usage across all mounted filesystems. - Use
du
when you want detailed information about specific folders or files within a filesystem.
Together, df
and du
offer a comprehensive picture of disk usage on a Linux system, helping with monitoring, troubleshooting, and managing disk space effectively.