一、df 命令简介
df
命令用于显示文件系统的磁盘空间利用情况,包括文件系统的总空间、已用空间、可用空间以及挂载点信息。通过df
命令,用户可以快速了解系统中各个文件系统的空间使用情况。
二、df 命令参数
bash
df [选项] [目录/驱动器]
选项:
-h
:以人类可读的格式显示输出。-T
:显示文件系统类型。-i
:显示inode使用情况。
目录/驱动器:指定要查询的文件或目录,如果未指定,则显示所有文件系统的使用情况。
三、df 命令示例
示例1:显示所有文件系统的磁盘空间利用情况:
bash
df
示例2:以人类可读的格式显示磁盘空间利用情况:
bash
df -h
示例3:显示指定文件系统的详细信息:
bash
df -T /dev/sda1
输出
bash
soulio@ubuntu:~<span class="katex--inline"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>d</mi><mi>f</mi><mo>−</mo><mi>h</mi><mi>F</mi><mi>i</mi><mi>l</mi><mi>e</mi><mi>s</mi><mi>y</mi><mi>s</mi><mi>t</mi><mi>e</mi><mi>m</mi><mi>S</mi><mi>i</mi><mi>z</mi><mi>e</mi><mi>U</mi><mi>s</mi><mi>e</mi><mi>d</mi><mi>A</mi><mi>v</mi><mi>a</mi><mi>i</mi><mi>l</mi><mi>U</mi><mi>s</mi><mi>e</mi><mi>t</mi><mi>m</mi><mi>p</mi><mi>f</mi><mi>s</mi><mn>197</mn><mi>M</mi><mn>1.2</mn><mi>M</mi><mn>196</mn><mi>M</mi><mn>1</mn><mi mathvariant="normal">/</mi><mi>d</mi><mi>e</mi><mi>v</mi><mi mathvariant="normal">/</mi><mi>s</mi><mi>d</mi><mi>a</mi><mn>232</mn><mi>G</mi><mn>13</mn><mi>G</mi><mn>18</mn><mi>G</mi><mn>43</mn><mi>t</mi><mi>m</mi><mi>p</mi><mi>f</mi><mi>s</mi><mn>982</mn><mi>M</mi><mn>0982</mn><mi>M</mi><mn>0</mn><mi>t</mi><mi>m</mi><mi>p</mi><mi>f</mi><mi>s</mi><mn>5.0</mn><mi>M</mi><mn>05.0</mn><mi>M</mi><mn>0</mn><mi>t</mi><mi>m</mi><mi>p</mi><mi>f</mi><mi>s</mi><mn>197</mn><mi>M</mi><mn>4.0</mn><mi>K</mi><mn>197</mn><mi>M</mi><mn>1</mn><mi>s</mi><mi>o</mi><mi>u</mi><mi>l</mi><mi>i</mi><mi>o</mi><mi mathvariant="normal">@</mi><mi>u</mi><mi>b</mi><mi>u</mi><mi>n</mi><mi>t</mi><mi>u</mi><mo>:</mo><mtext> </mtext></mrow><annotation encoding="application/x-tex"> df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 197M 1.2M 196M 1% /run
/dev/sda2 32G 13G 18G 43% /
tmpfs 982M 0 982M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 197M 4.0K 197M 1% /run/user/1000
soulio@ubuntu:~</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"><span class="mord mathnormal" style="margin-right:0.10764em;">df</span><span class="mspace" style="margin-right:0.2222em;"><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"><span class="mord mathnormal">h</span><span class="mord mathnormal" style="margin-right:0.13889em;">F</span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">esys</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mord mathnormal">m</span><span class="mord mathnormal" style="margin-right:0.05764em;">S</span><span class="mord mathnormal">i</span><span class="mord mathnormal">ze</span><span class="mord mathnormal" style="margin-right:0.10903em;">U</span><span class="mord mathnormal">se</span><span class="mord mathnormal">d</span><span class="mord mathnormal">A</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord mathnormal">ai</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal" style="margin-right:0.10903em;">U</span><span class="mord mathnormal">se</span><span class="mord mathnormal">t</span><span class="mord mathnormal">m</span><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">s</span><span class="mord">197</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord">1.2</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord">196</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord">1/</span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord">/</span><span class="mord mathnormal">s</span><span class="mord mathnormal">d</span><span class="mord mathnormal">a</span><span class="mord">232</span><span class="mord mathnormal">G</span><span class="mord">13</span><span class="mord mathnormal">G</span><span class="mord">18</span><span class="mord mathnormal">G</span><span class="mord">43</span><span class="mord mathnormal">t</span><span class="mord mathnormal">m</span><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">s</span><span class="mord">982</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord">0982</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord">0</span><span class="mord mathnormal">t</span><span class="mord mathnormal">m</span><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">s</span><span class="mord">5.0</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord">05.0</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord">0</span><span class="mord mathnormal">t</span><span class="mord mathnormal">m</span><span class="mord mathnormal">p</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">s</span><span class="mord">197</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord">4.0</span><span class="mord mathnormal" style="margin-right:0.07153em;">K</span><span class="mord">197</span><span class="mord mathnormal" style="margin-right:0.10903em;">M</span><span class="mord">1</span><span class="mord mathnormal">so</span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">i</span><span class="mord mathnormal">o</span><span class="mord">@</span><span class="mord mathnormal">u</span><span class="mord mathnormal">b</span><span class="mord mathnormal">u</span><span class="mord mathnormal">n</span><span class="mord mathnormal">t</span><span class="mord mathnormal">u</span><span class="mspace" style="margin-right:0.2778em;"><span class="mrel">:</span><span class="mspace nobreak"> </span></span></span></span></span> df -T /dev/sda2
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 ext4 32844560 13129596 18021012 43% /
</span></span></span></span></span>
注意事项
- 可以结合其他命令(如
grep
)来过滤df
命令的输出,以便查找特定信息。 - 确保有足够的权限来运行
df
命令,以便获取正确的磁盘空间信息。
df
命令是管理Linux系统中磁盘空间的重要工具,通过它可以及时监控文件系统的空间使用情况,帮助用户合理安排磁盘空间,避免因空间不足而导致的问题。