监控系统资源:`df`、`du`、`free`
检查磁盘空间、目录大小和内存使用情况,让系统保持良好状态。
监控系统资源:`df`、`du`、`free` 是 CoddyKit 上的免费 Linux Command Line Mastery 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Linux Command Line Mastery 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Linux Command Line Mastery 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Why Monitor System Resources?
Keeping an eye on your system's resources is crucial for smooth operation. Just like a car needs fuel and oil, your computer needs enough disk space and memory to run efficiently.
Ignoring these can lead to slow performance, crashes, or even data loss.
Check Disk Space with `df`
The df command, short for "disk free", reports the amount of available disk space used by file systems.
It's your go-to command to see how much room is left on your partitions.
`df` Command in Action
Let's try df with the -h option for human-readable output. This makes sizes like gigabytes (GB) and megabytes (MB) easy to understand.
Run this command in your terminal:
df -hInterpreting `df` Results
The output of df -h shows several columns:
- Filesystem: The name of the disk partition.
- Size: Total capacity of the partition.
- Used: Space currently occupied.
- Avail: Remaining free space.
- Use%: Percentage of disk space used.
- Mounted on: Where the filesystem is accessible in the directory tree.
Disk Usage with `du`
While df shows overall disk free space, du ("disk usage") estimates file space usage, primarily for specific files or directories.
It helps you find out which folders are taking up the most space.
`du` on a Directory
To see the total size of a directory in a human-readable format, use -s (summary) and -h (human-readable) with du. Replace /var/log with any directory you want to check.
du -sh /var/logDetailed `du` Output
Want to see the size of subdirectories within a folder? Use --max-depth=N to limit the depth of the output. Here, we'll see direct subdirectories (depth 1).
du -h --max-depth=1 /home/userMonitor Memory with `free`
Memory (RAM) is vital for your system's speed. The free command displays the total amount of free and used physical and swap memory in the system.
Keeping an eye on free memory helps prevent slowdowns.
`free -h` in Practice
Similar to df, using the -h option with free provides output that's much easier to read. It shows memory in KB, MB, or GB.
free -hResource Monitoring Check
You're running low on disk space and want to find which large directories are consuming it. Which command is best suited for this task?
Recap: System Resources
Great job! In this lesson, you learned how to monitor your Linux system's vital resources:
df: Check overall disk free space.du: Estimate disk usage for files and directories.free: Monitor physical and swap memory usage.
These commands are essential tools for maintaining a healthy and optimized system!
常见问题解答
「监控系统资源:`df`、`du`、`free`」课时是免费的吗?
是的 — 「监控系统资源:`df`、`du`、`free`」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Linux Command Line Mastery 课程的其余内容,请升级到 CoddyKit PRO。 Linux Command Line Mastery 课程共包含 4 节课。
「监控系统资源:`df`、`du`、`free`」这节课中我会学到什么?
检查磁盘空间、目录大小和内存使用情况,让系统保持良好状态。 你通过在浏览器中直接运行的动手代码来练习 Linux Command Line Mastery,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Linux Command Line Mastery 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Linux Command Line Mastery 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。
「监控系统资源:`df`、`du`、`free`」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Linux Command Line Mastery 课中编写并运行代码吗?
能。每节 Linux Command Line Mastery 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 理解进程:`ps`、`top`、`htop`
- 管理进程:`kill`、`bg`、`fg`
- 监控系统资源:`df`、`du`、`free`
- 使用 nice、renice 与信号管理进程优先级