如何在 Linux 上检查可用的磁盘空间
磁盘

> 
> 我已经使用了多少磁盘空间？
> 
> 
> 


![](/data/attachment/album/202011/17/111346h0vrdvldsy6hlhlh.jpg)


在 Linux 上查找可用磁盘空间的最简单的方法是[使用 df 命令](https://linuxhandbook.com/df-command/) 。`df` 命令从字面意思上代表着<ruby> 磁盘可用空间 <rt>  disk free </rt></ruby>，很明显，它将向你显示在 Linux 系统上的可用磁盘空间。



```
df -h

```

使用 `-h` 选项，它将以人类可读的格式（MB 和 GB）来显示磁盘空间。


这里是针对我 Dell XPS 系统的 `df` 命令的输出，它使用了加密磁盘并且只安装了 Linux：


![在 Linux 中使用 df 命令检查可用磁盘空间](/data/attachment/album/202011/17/111415ep0wcwezfo7r9wgp.png)


如果上面的输出使你感到困惑，不用担心。我将介绍一些关于在 Linux 中检查可用磁盘空间的东西。我也将为桌面 Linux 用户展示 GUI 方法。


### 方法 1: 使用 df 命令来检查在 Linux 中的可用磁盘空间（并理解它的输出）


当你使用 `df` 命令来检查磁盘空间时，它将显示一组“文件系统”，包括它们的大小、使用的空间和可用的空间。你实际的磁盘通常应该下面列表中的一个:


* `/dev/sda`
* `/dev/sdb`
* `/dev/nvme0n1p`


这不是硬性的标准，但是它可以给予你一个指示，它可以让你能够很容易地从一堆文字中辨别出真正的磁盘。


你的 Linux 系统在你的磁盘上可能有一些用于引导 分区、EFI 分区、根分区、交换分区、家目录等的分区。在这种情况下，这些分区在“磁盘名称”的结尾处使用一个数字来标示，像 `/dev/sda1`、`/dev/nvme0n1p2` 等等。


你可以从它们的挂载点来辨认出哪个分区是用于做什么的。根分区挂载在 `/`、EFI 分区在 `/boot/EFI` 等等。


就我的情况来说，我已经使用了根分区下磁盘空间（232 GB）的 41% 。如果你有 2 到 3 个大分区（像根分区、家目录分区等等），你将不得不在这里计算一下已使用的磁盘空间。


![理解 df 命令输出](/data/attachment/album/202011/17/111419q1ja1a1oav9oat9v.png)


* `tmpfs`：[tmpfs](https://www.kernel.org/doc/html/latest/filesystems/tmpfs.html)（临时文件系统）用于在虚拟存储器中保持文件。你可以随意地忽略这个虚拟文件系统。
* `udev`：[udev 文件系统](https://wiki.debian.org/udev) 用于存储插入到你系统的设备（像 USB、网卡、CD ROM 等等）的相关信息。你也可以忽略它。
* `/dev/loop`: 它们是环回设备。由于 snap 应用程序，在 Ubuntu 中查看磁盘时，你将看到很多的这样的设备。环回设备是虚拟设备，它们允许普通文件作为块设备文件来访问。使用环回设备，snap 应用程序在它们自己的虚拟磁盘中进行沙盒处理。尽管它们是在根分区下，但是你不需要单独计算它们使用的磁盘空间。


#### 丢失了磁盘空间？检查你是否挂载了所有是磁盘和分区


记住，`df` 命令仅显示已挂载文件系统的磁盘空间。如果你在同一块磁盘上使用多个 Linux 发行版（或者多个操作系统），或者在你的系统上有多个磁盘，你需要先挂载它们，以便查看在这些分区和磁盘上的可用磁盘空间。


例如，我的 [Intel NUC](https://itsfoss.com/install-linux-on-intel-nuc/) 有两个 SSD 磁盘，并且在其上有 4 个或 5 个 Linux 分区。仅当我明确地挂载它们时，`df` 命令才会显示更多磁盘。


![](/data/attachment/album/202011/17/111529q66vkkcqinqo7z5j.png)


你可以使用 `lsblk` 命令来查看在你系统上的所有磁盘和分区。


![](/data/attachment/album/202011/17/111428nzihr67wuqdy4u00.png)


在你有了磁盘分区名称后，你可以用这种方式来挂载它:



```
sudo mount /dev/sdb2 /mnt

```

我希望这种方法能够给你提供一个在 Linux 上检查硬盘驱动器空间的好主意。让我们看看如何在 GUI 下来完成。


### 方法 2: 在 GUI 下检查可用磁盘使用情况


在 Ubuntu 中使用 “Disk Usage Analyzer” 工具来在 GUI 的方式下检查可用磁盘空间是很容易的。


![Disk Usage Analyzer 工具](/data/attachment/album/202011/17/111431strcqtorxa0wrxrz.jpg)


在这里，你将看到所有实际的磁盘和分区。你可能需要单击一些分区来挂载它们。它显示所有已挂载分区的磁盘使用情况。


![磁盘使用情况检查](/data/attachment/album/202011/17/111433wfozjudjvuvswosj.png)


#### 使用 GNOME 的 Disks 实用程序来检查可用磁盘空间


除此之外，GNOME 的 Disks 实用程序也是非常容易使用的工具。


![GNOME 的 Disks 工具](/data/attachment/album/202011/17/111436mfzrgfers1jra1ea.jpg)


启动工具和选择磁盘。选择一个分区来查看可用磁盘空间。如果没有挂载分区，那么先通过单击 “▶” 图标来挂载它。


![检查 Ubuntu 的桌面版本的可用磁盘空间](/data/attachment/album/202011/17/111439d008nk80uwpuok6v.png)


我认为在 Linux 上的所有主要桌面环境都有某种图形工具来检查磁盘使用情况。你可以在你是桌面 Linux 系统的菜单中搜索它。


### 结束语


当然，有很多方法和工具来检查磁盘空间。为此，我向你显示了最常用的命令行方法和 GUI 方法。


我也解释一些可能会让你很难理解磁盘使用情况的东西。希望你喜欢它。


如果你有问题或建议，请在评论区告诉我。




---


via: <https://itsfoss.com/check-free-disk-space-linux/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[robsean](https://github.com/robsean) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

**How much disk space have I utilized?**

The simplest way to find the free disk space on Linux is to [use df command](https://linuxhandbook.com/df-command/). The df command stands for disk-free and quite obviously, it shows you the free and available disk space on Linux systems.

`df -h`


With `-h`

option, it shows the disk space in human-readable format (MB and GB).

Here’s the output of the df command for my Dell XPS system that has only Linux installed with encrypted disk:

![Free Disk Space Linux Df Command Output](https://itsfoss.com/content/images/wordpress/2020/11/free-disk-space-linux-df-command-output.png)

If the above output is confusing for you, don’t worry. I’ll explain a few things about checking available disk space on Linux. *I’ll also show the GUI method for desktop Linux users.*

Overall, I’ll mention three methods:

With the information you gather, you can go about [making some free space on Ubuntu](https://itsfoss.com/free-up-space-ubuntu-linux/).

## Method 1: Checking free disk space in Linux with df command (and understanding its output)

When you use the df command to check disk space, it will show a bunch of ‘file systems’ with their size, used space and free space. Your actual disks should normally be listed as one of the following:

- /dev/sda
- /dev/sdb
- /dev/nvme0n1p

This is not a hard and fast rule but it gives you an indication to easily recognize the actual disk from the crowd.

Your Linux system might have several partitions on your disk for boot, EFI, root, swap, home etc. In such cases, these partitions are reflected with a number at the end of the ‘disk name’, like /dev/sda1, /dev/nvme0n1p2 etc.

You could identify which partition is used for what purpose from its mount point. Root is mounted on /, EFI in /boot/EFI etc.

In my case, I have used 41% of the 232 GB of disk space under root. If you have 2-3 big partitions (like root, home etc), you’ll have to make a calculation here.

![Df Command Output](https://itsfoss.com/content/images/wordpress/2020/11/df-command-output.png)

**tmpfs**: The[tmpfs](https://www.kernel.org/doc/html/latest/filesystems/tmpfs.html)(temporary filesystem) used for keeping files in virtual memory. You can ignore this virtual filesystem comfortably.**udev**: The[udev filesystem](https://wiki.debian.org/udev)is used for storing information related to devices (like USB, network card, CD ROM etc) plugged to your system. You may ignore it as well.**/dev/loop**: These are loop devices. You’ll see plenty of them while checking disk space in Ubuntu because of snap applications. Loops are virtual devices that allow normal files to be accessed as block devices. With the loop devices, snap applications are sandboxed in their own virtual disk. Since they are under root, you don’t need to count their used disk space separately.

And, if you want to view the disk usage with more details like filesystem type and blocks, you can use the command:

`df -T`


![df t command](https://itsfoss.com/content/images/wordpress/2022/05/df-T-Command-800x262.png)

### Missing disk space? Check if you have mounted all disks and partitions

Keep in mind that the df command only shows disk space for mounted filesystems. If you are using more than one Linux distribution (or operating systems) on the same disk or you have multiple disks on your system, you need to mount them first in order to see the free space available on those partitions and disks.

For example, my [Intel NUC](https://itsfoss.com/install-linux-on-intel-nuc/) has two SSDs and 4 or 5 Linux distributions installed on them. It shows additional disks only when I mount them explicitly.

You can use the lsblk command to see all the disks and partitions on your system.

![Lsblk Command To See Disks Linux](https://itsfoss.com/content/images/wordpress/2020/11/lsblk-command-to-see-disks-linux.png)

Once you have the disk partition name, you can mount it in this fashion:

`sudo mount /dev/sdb2 /mnt`


I hope this gives you a pretty good idea about checking hard drive space on Linux. Let’s see how to do it graphically.

## Method 2: Using du, ls, and Other Commands

While df command is quite popular and should be enough for the use case, there are other alternatives that you can try including:

**du -h**→ Shows disk usage in human-readable format for all directories and subdirectories.**du -a**→Shows disk usage for all files.**du -s**Provides the total disk space used by a particular file or directory.**ls -al**→Lists the entire contents, along with their size, of a particular directory.**stat <file/directory>**→Displays the size and other stats of a file/directory or a file system.**fdisk -l**→Shows disk size along with disk partitioning information (may require sudo privileges).**dust**→ An interesting alternative to the**du**command written in Rust, available for Arch Linux in the repositories. For other Linux distros, you can refer to its[GitHub releases section](https://github.com/bootandy/dust).

## Method 3: Check free disk usage graphically

Checking free disk space graphically is much easier in Ubuntu with the Disk Usage Analyzer tool.

![Disk Usage Analyzer Tool Linux](https://itsfoss.com/content/images/wordpress/2020/11/disk-usage-analyzer-tool-linux.jpg)

You’ll see all the actual disks and partitions here. You may have to mount some partitions by clicking on them. It displays the disk usage for all the mounted partitions.

![Free Disk Space Ubuntu Desktop](https://itsfoss.com/content/images/wordpress/2020/11/free-disk-space-ubuntu-desktop-800x648.png)

### Checking free disk space with GNOME Disks utility

Otherwise, the GNOME Disks utility is also a pretty handy tool.

![Disks Tool Linux](https://itsfoss.com/content/images/wordpress/2020/11/disks-tool-linux.jpg)

Start the tool and select the disk. Select a partition to see the free disk space. If a partition is not mounted, mount it first by clicking the ‘play’ icon.

![Free Disk Space Check Ubuntu Desktop](https://itsfoss.com/content/images/wordpress/2020/11/free-disk-space-check-ubuntu-desktop.png)

I think all major desktop environments have some sort of graphical tool to check the disk usage on Linux. You can search for it in the menu of your desktop Linux system.

## Conclusion

Of course, there can be more ways and tools to check disk space. I showed you the most common command line and GUI methods for this purpose.

I also explained a few things that might trouble you in understanding disk usage. I hope you like it.

Running out of disk space? How about cleaning it up and get it back?

[7 Simple Ways to Free Up Space on Ubuntu and Linux MintBrief: Running out of space on your Linux system? Here are several ways you can clean up your system to free up space on Ubuntu and other Ubuntu based Linux distributions. Over time, any operating system can become cluttered as programs are added and removed. If you have like a](https://itsfoss.com/free-up-space-ubuntu-linux/)![](https://itsfoss.com/content/images/wordpress/2017/06/free-up-space-ubuntu-linux-featured.jpg)


![](https://itsfoss.com/content/images/wordpress/2017/06/free-up-space-ubuntu-linux-featured.jpg)

Please let me know in the comment section if you have questions or suggestions.