mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-21 02:10:11 +08:00
翻译完成
This commit is contained in:
parent
2fb92504da
commit
f0623d510d
@ -1,155 +0,0 @@
|
||||
[#]: subject: "Check disk usage in Linux"
|
||||
[#]: via: "https://opensource.com/article/22/7/check-disk-usage-linux"
|
||||
[#]: author: "Don Watkins https://opensource.com/users/don-watkins"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "MjSeven"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Check disk usage in Linux
|
||||
======
|
||||
The du and ncdu commands provide two different views of the same information, making it easy to keep track of what's stored on your computer.
|
||||
|
||||
![Data stack in blue][1]
|
||||
|
||||
Knowing how much of your disk is being used by your files is an important consideration, no matter how much storage you have. My laptop has a relatively small 250GB NVME drive. That's okay most of the time, but I began to explore gaming on Linux a couple of years ago. Installing Steam and a few games can make storage management more critical.
|
||||
|
||||
### The du command
|
||||
|
||||
The easiest way to examine what's left for storage on your disk drive is the [du command][2]. This command line utility estimates file space usage. Like all Linux tools, `du` is very powerful, but knowing how to use it for your particular needs is helpful. I always consult the man page for any utility. This specific tool has several switches to give you the best possible snapshot of file storage and how much space they consume on your system.
|
||||
|
||||
There are many options for the `du` command. Here are some of the common ones:
|
||||
|
||||
* -a - write counts for all files and not just directories
|
||||
* --apparent-size - prints apparent sizes rather than disk usage
|
||||
* -h - human-readable format
|
||||
* -b - bytes
|
||||
* -c -grand total
|
||||
* -k - block size
|
||||
* -m - size in megabytes
|
||||
|
||||
Be sure to check the `du` man page for a complete listing.
|
||||
|
||||
#### Display all files
|
||||
|
||||
The first option you could choose is `du -a`. It provides a readout of all files on your system and the directories they are stored in. This command lets me know I've got 11555168 bytes stored in my home directory. Using `du -a` provides a quick recursive look at my storage system. What if I want a more meaningful number, and I want to drill down into the directories to see where the big files are on my system?
|
||||
|
||||
I think there are some big files in my `Downloads` directory, so I enter `du -a /home/don/Downloads` to get a good look at that `Downloads` directory.
|
||||
|
||||
```
|
||||
$ du -a ~/Downloads
|
||||
4923 ./UNIX_Driver_5-0/UNIX Driver 50
|
||||
4923 ./UNIX_Driver_5-0
|
||||
20 ./epel-release-latest-9.noarch.rpm
|
||||
12 ./rpmfusion-free-release-9.noarch.rpm
|
||||
2256 ./PZO9297 000 Cover.pdf
|
||||
8 ./pc.md
|
||||
2644 ./geckodriver-v0.31.0-linux64.tar.gz
|
||||
466468
|
||||
```
|
||||
|
||||
The numbers on the far left are the file sizes in bytes. I want something more helpful to me so I add the switch for the human-readable format to my `du -h /home/don/Downloads` command. The result is 4.8 G(igabytes) which is a more useful number format for me.
|
||||
|
||||
```
|
||||
$ du -a ~/Downloads
|
||||
4.9M ./UNIX_Driver_5-0/UNIX Driver 50
|
||||
4.9M ./UNIX_Driver_5-0
|
||||
20K ./epel-release-latest-9.noarch.rpm
|
||||
12K ./rpmfusion-free-release-9.noarch.rpm
|
||||
2.2M ./PZO9297 000 Cover.pdf
|
||||
8.0K ./pc.md
|
||||
2.6M ./geckodriver-v0.31.0-linux64.tar.gz
|
||||
456M .
|
||||
```
|
||||
|
||||
As with most Linux commands, you can combine options. To look at your `Downloads` directory in a human-readable format, use the `du -ah ~/Downloads` command.
|
||||
|
||||
**[[ Read also: 5 Linux commands to check free disk space ]][3]**
|
||||
|
||||
#### Grand total
|
||||
|
||||
The `-c` option provides a grand total for disk usage at the last line. I can use `du -ch /home/don` to display every file and directory in my home directory. There is a lot of information, and I really just want what is at the end, so I will pipe the disk usage command to `tail`. The command is `du -ch /home/don | tail`.
|
||||
|
||||
![pipe the du command output into tail][4]
|
||||
|
||||
Image by:
|
||||
|
||||
(Don Watkins, CC BY-SA 4.0)
|
||||
|
||||
### The ncdu command
|
||||
|
||||
Another option for Linux users interested in what is stored on their drive is the [ncdu command][5]. The command stands for *NCurses Disk Usage*. Depending on your Linux distribution, you may need to download and install it.
|
||||
|
||||
On Linux Mint, Elementary, Pop_OS!, and other Debian-based distributions:
|
||||
|
||||
```
|
||||
$ sudo apt install ncdu
|
||||
```
|
||||
|
||||
On Fedora, Mageia, and CentOS:
|
||||
|
||||
```
|
||||
$ sudo dnf install ncdu
|
||||
```
|
||||
|
||||
On Arch, Manjaro, and similar:
|
||||
|
||||
```
|
||||
$ sudo pacman -S ncdu
|
||||
```
|
||||
|
||||
Once installed, you can use `ncdu` to analyze your filesystem. Here is a sample output after issuing `ncdu` inside my home directory. The man page for `ncdu` states that "ncdu (NCurses Disk Usage) is a curses-based version of the well-known `du`, and provides a fast way to see what directories are using your disk space."
|
||||
|
||||
![du command home directory output][6]
|
||||
|
||||
Image by:
|
||||
|
||||
(Don Watkins, CC BY-SA 4.0)
|
||||
|
||||
I can use the arrow keys to navigate up and down and press the **Enter** key to enter a directory. An interesting note is that `du` reported total disk usage in my home directory as 12GB, and `ncdu` reports that I have total disk usage of 11GB. You can find more information in the `ncdu` man page.
|
||||
|
||||
You can explore a particular directory by pointing `ncdu` to that directory. For example, `ncdu /home/don/Downloads`.
|
||||
|
||||
![ncdu command output][7]
|
||||
|
||||
Image by:
|
||||
|
||||
(Don Watkins, CC BY-SA 4.0)
|
||||
|
||||
Press the **?** key to display the Help menu
|
||||
|
||||
![ncdu help][8]
|
||||
|
||||
Image by:
|
||||
|
||||
(Don Watkins, CC BY-SA 4.0)
|
||||
|
||||
### Wrap up
|
||||
|
||||
The `du` and `ncdu` commands provide two different views of the same information, making it easy to keep track of what's stored on your computer.
|
||||
|
||||
If you're not comfortable in the terminal or just looking for yet another view of this kind of information, check out the [GNOME Disk Usage Analyzer][9]. You can easily install and use it if it's not already on your system. Check your distribution for `baobab` and install it if you'd like to experiment.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/22/7/check-disk-usage-linux
|
||||
|
||||
作者:[Don Watkins][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/don-watkins
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://opensource.com/sites/default/files/lead-images/data_stack_blue_disks.png
|
||||
[2]: https://opensource.com/article/21/7/check-disk-space-linux-du
|
||||
[3]: https://opensource.com/article/18/7/how-check-free-disk-space-linux
|
||||
[4]: https://opensource.com/sites/default/files/2022-06/1-du-tail.png
|
||||
[5]: https://opensource.com/article/21/8/ncdu-check-free-disk-space-linux
|
||||
[6]: https://opensource.com/sites/default/files/2022-06/2home.png
|
||||
[7]: https://opensource.com/sites/default/files/2022-06/3downloads.png
|
||||
[8]: https://opensource.com/sites/default/files/2022-06/4ncdu.png
|
||||
[9]: https://help.gnome.org/users/baobab/stable/
|
155
translated/tech/20220707 Check disk usage in Linux.md
Normal file
155
translated/tech/20220707 Check disk usage in Linux.md
Normal file
@ -0,0 +1,155 @@
|
||||
[#]: subject: "Check disk usage in Linux"
|
||||
[#]: via: "https://opensource.com/article/22/7/check-disk-usage-linux"
|
||||
[#]: author: "Don Watkins https://opensource.com/users/don-watkins"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "MjSeven"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
检查 Linux 磁盘使用情况
|
||||
======
|
||||
du 和 ncdu 两个命令提供了相同信息的两种不同视图,便于我们跟踪存储在计算机上的内容。
|
||||
|
||||
![Data stack in blue][1]
|
||||
|
||||
无论你有多少存储空间,了解文件占用了多少磁盘空间都是一个重要的考虑事项。我的笔记本有一个相对较小的 250GB NVME 驱动器,大多数时候都没什么问题,但几年前我开始探索 Linux 上的游戏,情况变得有所不同,安装 Steam 和其他游戏使存储管理更加重要。
|
||||
|
||||
### du 命令
|
||||
|
||||
检查磁盘驱动器上剩余存储空间最简单的方法是 [du 命令][2]。它会估计文件空间使用情况,像其他所有 Linux 工具一样,`du` 非常强大,但知道如何根据你的特定需求使用它会很有帮助。我总是查阅 man 页面来获取实用程序。du 有几个选项,可以为你提供文件存储的最佳快照,以及它们在系统上消耗多少空间。
|
||||
|
||||
`du` 命令有很多选项,以下是一些常见的:
|
||||
|
||||
* -a - 包括文件夹和文件在内的存储信息
|
||||
* --apparent-size - 打印自身大小而不是占用磁盘量
|
||||
* -h - 人类可读的格式
|
||||
* -b - 字节
|
||||
* -c -总计
|
||||
* -k - 块大小
|
||||
* -m - 以兆字节为单位的大小
|
||||
|
||||
务必查看 `du` 手册页获取完整帮助列表。
|
||||
|
||||
#### 显示所有文件
|
||||
|
||||
你可以选择的第一个选项是 `du -a`,它可以显示系统上所有文件及其存储目录的大小。这个命令让我知道了我的主目录中存储了 11555168 个字节。使用 `du -a` 可以快速递归地查看我的存储系统。如果我想要一个更有意义的数字,并且我想深入到目录中查看大文件的位置,该怎么办?
|
||||
|
||||
我认为在 `Downloads` 目录下有一些大文件,所以我输入 `du -a /home/don/Downloads` 来查看。
|
||||
|
||||
```
|
||||
$ du -a ~/Downloads
|
||||
4923 ./UNIX_Driver_5-0/UNIX Driver 50
|
||||
4923 ./UNIX_Driver_5-0
|
||||
20 ./epel-release-latest-9.noarch.rpm
|
||||
12 ./rpmfusion-free-release-9.noarch.rpm
|
||||
2256 ./PZO9297 000 Cover.pdf
|
||||
8 ./pc.md
|
||||
2644 ./geckodriver-v0.31.0-linux64.tar.gz
|
||||
466468
|
||||
```
|
||||
|
||||
最左边的数字是以字节为单位的文件大小。我想要一些对我更有帮助的东西,所以我将人类可读格式的选项添加到命令中,结果是 4.8G(千兆字节),这对我来说是一种更有用的数字格式。(to 校正:这个 4.8G 不知道从何而来)
|
||||
|
||||
```
|
||||
$ du -ah ~/Downloads
|
||||
4.9M ./UNIX_Driver_5-0/UNIX Driver 50
|
||||
4.9M ./UNIX_Driver_5-0
|
||||
20K ./epel-release-latest-9.noarch.rpm
|
||||
12K ./rpmfusion-free-release-9.noarch.rpm
|
||||
2.2M ./PZO9297 000 Cover.pdf
|
||||
8.0K ./pc.md
|
||||
2.6M ./geckodriver-v0.31.0-linux64.tar.gz
|
||||
456M .
|
||||
```
|
||||
|
||||
与大多数 Linux 命令一样,你可以组合选项,要以人类可读的格式查看 `Downloads` 目录,使用 `du -ah ~/Downloads` 命令。
|
||||
|
||||
**[[ 另请阅读:检查可用磁盘空间的 5 个 Linux 命令 ]][3]**
|
||||
|
||||
#### 总和
|
||||
|
||||
`-c` 选项在最后一行提供了磁盘使用总和。我可以使用 `du -ch /home/don` 来显示主目录中的每个文件和目录。这里有很多信息,我只想知道最后一行的信息,所以我将磁盘使用命令通过管道传输给 `tail`。命令是 `du -ch /home/don | tail`。(to 校正:这条命令似乎没卵用,在 Ubuntu 试验过)
|
||||
|
||||
![将 du 命令输出通过管道传输到 tail][4]
|
||||
|
||||
Image by:
|
||||
|
||||
(Don Watkins, CC BY-SA 4.0)
|
||||
|
||||
### ncdu 命令
|
||||
|
||||
对存储在驱动器上内容感兴趣的 Linux 用户,另一个选择是 [ncdu 命令][5],它代表 *NCurses 磁盘使用情况*。基于你的 Linux 发行版,你可能需要下载并安装它。
|
||||
|
||||
在 Linux Mint、Elementary、Pop_OS! 或其它基于 Debian 的发行版上:
|
||||
|
||||
```
|
||||
$ sudo apt install ncdu
|
||||
```
|
||||
|
||||
在 Fedora、Mageia 或 CentOS 上:
|
||||
|
||||
```
|
||||
$ sudo dnf install ncdu
|
||||
```
|
||||
|
||||
在 Arch、Manjar 或者类似发行版上:
|
||||
|
||||
```
|
||||
$ sudo pacman -S ncdu
|
||||
```
|
||||
|
||||
安装后,你可以使用 ncdu 来分析你的文件系统。以下是在我的主目录中发出 `ncdu` 后的示例输出。`ncdu` 的 man 页面指出“ncdu(NCurses Disk Usage)是众所周知的 `du` 基于 curses 的版本,它提供了一种快速查看哪些目录正在使用磁盘空间的方法。”
|
||||
|
||||
![du 命令输出][6]
|
||||
|
||||
Image by:
|
||||
|
||||
(Don Watkins, CC BY-SA 4.0)
|
||||
|
||||
我可以使用方向键上下导航,按下 **Enter** 键进入目录。有趣的是,`du` 报告我的主目录中的总磁盘使用量为 12GB,而 `ncdu` 显示为 11GB。你可以在 `ncdu` 手册页中找到更多信息。
|
||||
|
||||
你可以将 `ncdu` 指向某个目录来探索特定目录。例如,`ncdu /home/don/Downloads`。
|
||||
|
||||
![ncdu 命令输出][7]
|
||||
|
||||
Image by:
|
||||
|
||||
(Don Watkins, CC BY-SA 4.0)
|
||||
|
||||
按 **?** 键显示帮助菜单。
|
||||
|
||||
![ncdu 帮助][8]
|
||||
|
||||
Image by:
|
||||
|
||||
(Don Watkins, CC BY-SA 4.0)
|
||||
|
||||
### 总结
|
||||
|
||||
`du` 和 `ncdu` 两个命令提供了相同信息的两种不同视图,便于我们跟踪存储在计算机上的内容。
|
||||
|
||||
如果你不习惯使用终端,或者只是在寻找此类信息的另一种试图,查看 [GNOME 磁盘使用分析器][9]。如果你的系统上还没有它,你可以轻松安装和使用它。检查你的发行版是否有 `baobab`,如果你想进行尝试,去安装它。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/22/7/check-disk-usage-linux
|
||||
|
||||
作者:[Don Watkins][a]
|
||||
选题:[lkxed][b]
|
||||
译者:[MjSeven](https://github.com/MjSeven)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/don-watkins
|
||||
[b]: https://github.com/lkxed
|
||||
[1]: https://opensource.com/sites/default/files/lead-images/data_stack_blue_disks.png
|
||||
[2]: https://opensource.com/article/21/7/check-disk-space-linux-du
|
||||
[3]: https://opensource.com/article/18/7/how-check-free-disk-space-linux
|
||||
[4]: https://opensource.com/sites/default/files/2022-06/1-du-tail.png
|
||||
[5]: https://opensource.com/article/21/8/ncdu-check-free-disk-space-linux
|
||||
[6]: https://opensource.com/sites/default/files/2022-06/2home.png
|
||||
[7]: https://opensource.com/sites/default/files/2022-06/3downloads.png
|
||||
[8]: https://opensource.com/sites/default/files/2022-06/4ncdu.png
|
||||
[9]: https://help.gnome.org/users/baobab/stable/
|
Loading…
Reference in New Issue
Block a user