Managing disk space is a fundamental task for any Linux user or administrator. Two essential commands for this purpose are df and du. Let's explore how to use them to monitor your disk utilization effectively.
Checking Filesystem Space with df
The df (disk free) command reports the amount of disk space used and available on your currently mounted filesystems. It provides a high-level overview of your storage.
To get a report in a human-readable format (e.g., GB, MB, KB), use the -h flag:
pete@icebox:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 6.2G 2.3G 3.6G 40% /
This output shows the filesystem device, total size, used space, available space, the percentage of use, and where it is mounted.
Analyzing Inode Usage
Besides block space, filesystems also use inodes to store metadata about files (like permissions, ownership, and location). On rare occasions, you can run out of inodes even if you have free disk space. To check inode usage, you can use the df -i command. Running df -i in Linux gives you a clear picture of inode allocation.
pete@icebox:~$ df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 4128768 128768 4000000 4% /
Summarizing Directory Usage with du
When you notice a disk is getting full, you'll want to identify which files or directories are consuming the most space. For this task, the du (disk usage) command is the perfect tool.
Running du without arguments shows the disk usage for each subdirectory in your current location. Using the -h flag provides a human-readable summary:
du -h
You can also specify a path, like du -h /home/pete, to analyze a specific directory. Running it on the root directory (du -h /) can produce a lot of output, so it's often better to check specific directories you suspect are large.
df vs du A Quick Summary
The syntax for df and du is so similar that it can be easy to mix them up. Here’s a simple way to remember the difference:
- Use
dfto check how much disk is free on your filesystems. - Use
duto check the disk usage of specific files and directories.