"Data replication and capacity management" perfectly describes my first years in the enterprise support environment. While I enjoyed becoming a replication SME, I always hated looking into capacity issues. This dislike was in part because capacity issues were almost always ignored until a customer was in full meltdown data loss mode. It was also due to the fact that working with compression algorithms and de-duplication can make storage capacity a bit tricky.

As a junior support engineer, I found myself using the df and du commands to figure out why I couldn't apply a system patch, or exactly where all of the data crowding was occurring. Today, we will look at these commands, break them down into their use cases, and explain the discrepancy between the two. 

df

The "disk free" command is a fantastic command-line tool that gives you a quick 30,000-foot view of your filesystem and all mounted disks. It tells you the total disk size, space used, space available, usage percentage, and what partition the disk is mounted on. I recommend pairing it with the -h flag to make the data human-readable. The figures that you see here are calculated from the mount point or filesystem level:

df -h run on my /home/user directory

Also, note that using the -h flag rounds your data to make it easier to digest, so your 3G might be close to 2.9G or 3.1G. You can't be sure. 

du

The "disk usage" command is excellent when applied in the correct context. This command is at its best when you need to see the size of a given directory or subdirectory. It runs at the object level and only reports on the specified stats at the time of execution. I like to pair this command with the -sh flags to give a human-readable summary of a specified object (the directory and all subdirectories), as you can see here:

du -sh on /home/user directory

df vs. du

So what are the use cases for each command and which command's output should you put your trust into? The (very complicated) answer can be best summarized like this: The df command provides a sweeping ballpark figure for how much space is being utilized on your filesystem as a whole. The du command is a much more accurate snapshot of a given directory or subdirectory.

If I had to put money on which command was telling the "truth," I would bet on du. For example, if I get an error trying to install a package in /var that says the directory is full, I can run the df command to confirm that this is true. Once I can see that /var is at capacity, I can run du /var to see what subdirectory is giving me the issue. I could then continue to use df to narrow down by subdirectory until I found the culprit.

Understanding the differences in these commands allows us to use these tools in tandem to quickly identify and solve the majority of capacity issues that we face as sysadmins. 

Want to try out Red Hat Enterprise Linux? Download it now for free. 


关于作者

Tyler is the Sr. Community Manager at Enable Sysadmin, a submarine veteran, and an all-round tech enthusiast! He was first introduced to Red Hat in 2012 by way of a Red Hat Enterprise Linux-based combat system inside the USS Georgia Missile Control Center. Now that he has surfaced, he lives with his wife and son near Raleigh, where he worked as a data storage engineer before finding his way to the Red Hat team. He has written numerous technical documents, from military procedures to knowledgebase articles and even some training curricula. In his free time, he blends a passion for hiking, climbing, and bushcraft with video games and computer building. He is loves to read and enjoy a scotch or bourbon. Find him on Twitter or on LinkedIn.

UI_Icon-Red_Hat-Close-A-Black-RGB

按频道浏览

automation icon

自动化

有关技术、团队和环境 IT 自动化的最新信息

AI icon

人工智能

平台更新使客户可以在任何地方运行人工智能工作负载

open hybrid cloud icon

开放混合云

了解我们如何利用混合云构建更灵活的未来

security icon

安全防护

有关我们如何跨环境和技术减少风险的最新信息

edge icon

边缘计算

简化边缘运维的平台更新

Infrastructure icon

基础架构

全球领先企业 Linux 平台的最新动态

application development icon

应用领域

我们针对最严峻的应用挑战的解决方案

Virtualization icon

虚拟化

适用于您的本地或跨云工作负载的企业虚拟化的未来