Disk Usage Analysis (df, du)
Disk usage analysis in Ubuntu can be performed using the df
and du
commands. Here's an explanation of both commands along with examples and outputs:
1. df
(Disk Free)
The df
command reports the amount of disk space used and available on all mounted filesystems. It’s commonly used to get an overview of the entire disk usage on your system.
Basic Usage:
df -h
Explanation:
-h
stands for "human-readable," which formats the output in a way that's easier to read (e.g., MB, GB).
Example Output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 15G 32G 33% /
/dev/sda2 100G 45G 51G 47% /home
tmpfs 1.6G 4.0K 1.6G 1% /run/user/1000
Explanation of Output:
- Filesystem: The name of the filesystem or partition.
- Size: Total size of the filesystem.
- Used: Amount of space used.
- Avail: Available space.
- Use%: Percentage of the disk space used.
- Mounted on: The mount point or directory where the filesystem is mounted.
2. du
(Disk Usage)
The du
command is used to estimate file space usage. It provides more detailed information about the disk space usage of files and directories within a specific directory.
Basic Usage:
du -h /path/to/directory
Explanation:
-h
stands for "human-readable," making the sizes easier to read.
Example Output:
4.0K /home/user/.config
8.0K /home/user/Documents/Project
20M /home/user/Documents
45G /home/user
Explanation of Output:
- First Column: Size of the directory or file.
- Second Column: Path to the directory or file.
Combined Usage Example:
To get a quick overview of how much space a specific directory is using, you can combine df
and du
.
Example:
df -h /home/user && du -sh /home/user/Documents
Output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 100G 45G 51G 47% /home
20M /home/user/Documents
Summary
df
gives an overview of the disk usage on mounted filesystems.du
provides detailed disk usage information for specific files or directories.
These commands are essential for monitoring and managing disk space, especially on systems where storage is limited.
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Copyright 2023-2025 © All rights reserved.