forked from yangpeng14/DevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yangpeng
committed
Jul 21, 2020
1 parent
07ad557
commit e5030a8
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
## 前言 | ||
|
||
不管是使用电脑还是维护服务器,都会遇到一个问题,磁盘空间不足。一般都是通过 `du` 命令来统计磁盘占用空间。 | ||
|
||
今天推荐一个非常好用的统计磁盘占用工具 `ncdu`。 | ||
|
||
> `ncdu` 项目地址 https://github.com/rofl0r/ncdu | ||
## ncdu 相对与 du 的优势 | ||
|
||
优势: | ||
|
||
- 统计的目录以仪表盘展示 | ||
- 可以以磁盘占用大小或者文件名称排序 | ||
- 支持远程导出本地分析 | ||
|
||
## 示例 | ||
|
||
### 命令格式 | ||
|
||
```bash | ||
ncdu <options> <directory> | ||
``` | ||
|
||
### 直接运行 ncdu | ||
|
||
直接运行 `ncdu` ,默认统计当前目录大小。 | ||
|
||
扫描中。。。 | ||
|
||
![扫描中](/img/ncdu-img-1.png) | ||
|
||
扫描结果,展示统计结果 | ||
|
||
![统计结果](/img/ncdu-img-2.png) | ||
|
||
显示目录信息 | ||
|
||
![目录信息](/img/ncdu-img-3.png) | ||
|
||
### 扫描 / 目录文件系统,需要使用 -x 参数: | ||
|
||
```bash | ||
$ ncdu -x / | ||
``` | ||
|
||
### 扫描整个文件系统,文件多可以把结果导出并压缩 | ||
|
||
```bash | ||
# 把结果导出并压缩 | ||
$ ncdu -1xo- / | gzip > out.gz | ||
|
||
# 查看结果 | ||
$ zcat out.gz | ncdu -f- | ||
``` | ||
|
||
### 扫描完成后,可以导出目录并浏览目录 | ||
|
||
```bash | ||
$ ncdu -o- | tee out.file | ncdu -f- | ||
``` | ||
|
||
### 远程扫描系统,本地浏览结果 | ||
|
||
```bash | ||
$ ssh -C user@host ncdu -o- /mnt | ncdu -f- | ||
``` | ||
|
||
## 参数选项 [1] | ||
|
||
下面例举几个常用的参数: | ||
|
||
- `-q`:静音模式。在扫描或导入目录时,默认情况下,ncdu 将每秒更新屏幕 `10` 次,在安静模式下,此间隔将减少为每 `2` 秒一次。使用此功能可以节省远程连接上的带宽。使用 `-0` 时,此选项无效。 | ||
- `-x`:请勿越过文件系统边界,即仅将与正在扫描的目录位于同一文件系统上的文件和目录计数。 | ||
- `-f FILE`:加载给定文件,该文件先前是使用 `-o` 选项创建的。如果 FILE 等效于 `-`,则从标准输入中读取文件。 | ||
- `-0`:扫描目录或导入文件时,不会提供任何反馈,除非发生致命错误。扫描完成之前,不会初始化 Ncurses。用 -o 导出数据时,ncurses 根本不会初始化。导出到标准输出时,此选项是默认选项。 | ||
- `-1`:类似于 `-0`,但仅以单行输出就扫描进度提供反馈。导出到文件时,此选项是默认选项。 | ||
- `-2`:在扫描目录或导入文件时,提供全屏 ncurses 界面。这是唯一在扫描时提供有关任何非致命错误的反馈的界面。 | ||
- `--exclude`:排除匹配的文件 | ||
|
||
## 仪表盘参数 | ||
|
||
扫描结果出来后,可以按 `?` 显示帮助: | ||
|
||
![帮助](/img/ncdu-img-4.png) | ||
|
||
常用快捷键: | ||
|
||
- `n`:按文件名进行排序 | ||
- `s`:按文件大小进行排序 | ||
- `r`:重新统计当前文件夹大小 | ||
- `g`:用#或百分比显示各文件/目录的大小所占的百分比 | ||
- `i`:显示当前文件/目录信息 | ||
|
||
## 参数文章 | ||
|
||
- [1] http://www.jokervtv.top/blog/linux%20commend/ncdu.html |