XAMPPRocky/tokei
GitHub: XAMPPRocky/tokei
一款基于 Rust 的高性能命令行代码统计工具,快速准确地按语言分类统计代码行、注释行与空白行。
Stars: 14158 | Forks: 666
# Tokei ([時計](https://en.wiktionary.org/wiki/%E6%99%82%E8%A8%88))
[](https://github.com/XAMPPRocky/tokei/actions?query=workflow%3A%22Mean+Bean+CI%22)
[](https://github.com/XAMPPRocky/tokei/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)
[](https://docs.rs/tokei/)



)
[](https://deps.rs/repo/github/XAMPPRocky/tokei)
[](https://repology.org/project/tokei/versions)
Tokei 是一个显示代码统计信息的程序。Tokei 会按语言分组显示文件数量、这些文件中的总行数以及代码、注释和空白的行数。
## 示例
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Language Files Lines Code Comments Blanks
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
BASH 4 49 30 10 9
JSON 1 1332 1332 0 0
Shell 1 49 38 1 10
TOML 2 77 64 4 9
───────────────────────────────────────────────────────────────────────────────
Markdown 5 1355 0 1074 281
|- JSON 1 41 41 0 0
|- Rust 2 53 42 6 5
|- Shell 1 22 18 0 4
(Total) 1471 101 1080 290
───────────────────────────────────────────────────────────────────────────────
Rust 19 3416 2840 116 460
|- Markdown 12 351 5 295 51
(Total) 3767 2845 411 511
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Total 32 6745 4410 1506 829
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
## [API 文档](https://docs.rs/tokei)
## 目录
- [功能特性](#features)
- [安装](#installation)
- [包管理器](#package-managers)
- [手动安装](#manual)
- [配置](#configuration)
- [如何使用 Tokei](#how-to-use-tokei)
- [选项](#options)
- [支持的语言](#supported-languages)
- [更新日志](CHANGELOG.md)
- [常见问题](#common-issues)
- [权威源](#canonical-source)
- [版权与许可](#copyright-and-license)
## 功能特性
- Tokei **非常快**,能够在几秒钟内计算数百万行代码。
查看 [11.0.0 版本](https://github.com/XAMPPRocky/tokei/releases/v11.0.0)
以了解 Tokei 的速度如何与其他工具进行比较。
- Tokei **准确**,Tokei 能正确处理多行注释,
嵌套注释,并且不会将字符串中的注释计入。提供准确的代码统计。
- Tokei 支持范围广泛的语言,支持超过 **150** 种语言,
及其各种扩展名。
- Tokei 可以以多种格式 (**CBOR**、**JSON**、**YAML**) 输出,
从而可以轻松地存储和重用 Tokei 的输出。这些也可以在 tokei 中重用,将上一次运行的统计信息与另一组统计信息结合。
- Tokei 可在 **Mac**、**Linux** 和 **Windows** 上使用。有关如何在你所用的平台上获取 Tokei 的信息,请参阅[安装说明](#installation)。
- Tokei 也是一个**库**,允许你轻松地将其与其他项目集成。
- Tokei 带有彩色和无彩色模式。将环境变量 NO_COLOR 设置为 1,
它将以黑白方式显示。
## 安装
### 包管理器
#### Unix
```
# Alpine Linux (自 3.13 起)
apk add tokei
# Arch Linux
pacman -S tokei
# Cargo
cargo install tokei
# Conda
conda install -c conda-forge tokei
# Fedora
sudo dnf install tokei
# FreeBSD
pkg install tokei
# NetBSD
pkgin install tokei
# Nix/NixOS
nix-env -i tokei
# OpenSUSE
sudo zypper install tokei
# Void Linux
sudo xbps-install tokei
```
#### macOS
```
# Homebrew
brew install tokei
# MacPorts
sudo port selfupdate
sudo port install tokei
```
#### Windows
```
# Winget
winget install XAMPPRocky.tokei
# Scoop
scoop install tokei
```
### 手动安装
#### 下载
你可以在
[发布版块](https://github.com/XAMPPRocky/tokei/releases) 下载预编译的二进制文件。
#### 构建
你也可以从源代码构建并安装(需要最新的稳定版 [Rust] 编译器)。
```
cargo install --git https://github.com/XAMPPRocky/tokei.git tokei
```
## 配置
Tokei 有一个 [配置] 文件,允许你更改默认行为。
该文件可以命名为 `tokei.toml` 或 `.tokeirc`。目前 tokei 会在三个不同的位置查找此文件:当前目录、你的主目录以及你的配置目录。
## 如何使用 Tokei
#### 基本用法
这是使用 tokei 的基本方法。它将报告 `./foo` 及其所有子文件夹中的代码情况。
```
$ tokei ./foo
```
#### 多个文件夹
要让 tokei 在同一次调用中报告多个文件夹的情况,只需将所有你希望 tokei 检查的文件夹添加进来即可。
```
$ tokei ./foo ./bar ./baz
```
#### 排除文件夹
Tokei 会遵循所有的 `.gitignore` 和 `.ignore` 文件,并且你可以使用 `--exclude` 选项来排除任何额外的文件。`--exclude` 标志的语义与 `.gitignore` 相同。
```
$ tokei ./foo --exclude *.rs
```
要排除的路径也可以列在 `.tokeignore` 文件中,使用与 .gitignore 文件相同的 [语法](https://git-scm.com/docs/gitignore)。
#### 对输出进行排序
默认情况下,tokei 按语言名称的字母顺序排序,但使用 `--sort` 选项,tokei 也可以按任何列进行排序。
`blanks, code, comments, lines`
```
$ tokei ./foo --sort code
```
#### 输出文件统计信息
默认情况下,tokei 仅输出语言的汇总,而使用 `--files` 标志,tokei 还可以输出单个文件的统计信息。
```
$ tokei ./foo --files
```
#### 输出为不同格式
Tokei 通常输出为适合终端阅读的、友好的人类可读格式。
此外,还可以使用 `--output` 选项以各种其他格式输出,这对于将数据导入其他程序更为有用。
**注意:** 此版本的 tokei 在编译时未包含任何序列化格式,要启用序列化功能,请使用 features 标志重新安装 tokei。
```
ALL:
cargo install tokei --features all
CBOR:
cargo install tokei --features cbor
YAML:
cargo install tokei --features yaml
```
**目前支持的格式**
- JSON `--output json`
- YAML `--output yaml`
- CBOR `--output cbor`
```
$ tokei ./foo --output json
```
#### 读入已存储的格式
Tokei 还可以接收之前结果中输出的格式,并将其添加到当前运行中。Tokei 可以接受一个文件路径、作为选项值传入的格式,或者从标准输入 读取。
```
$ tokei ./foo --input ./stats.json
```
## 选项
```
USAGE:
tokei [FLAGS] [OPTIONS] [--] [input]...
FLAGS:
-f, --files Will print out statistics on individual files.
-h, --help Prints help information
--hidden Count hidden files.
-l, --languages Prints out supported languages and their extensions.
--no-ignore Don't respect ignore files (.gitignore, .ignore, etc.). This implies --no-ignore-parent,
--no-ignore-dot, and --no-ignore-vcs.
--no-ignore-dot Don't respect .ignore and .tokeignore files, including those in parent directories.
--no-ignore-parent Don't respect ignore files (.gitignore, .ignore, etc.) in parent directories.
--no-ignore-vcs Don't respect VCS ignore files (.gitignore, .hgignore, etc.), including those in parent
directories.
-V, --version Prints version information
-v, --verbose Set log output level:
1: to show unknown file extensions,
2: reserved for future debugging,
3: enable file level trace. Not recommended on multiple files
OPTIONS:
-c, --columns Sets a strict column width of the output, only available for terminal output.
-e, --exclude ... Ignore all files & directories matching the pattern.
-i, --input Gives statistics from a previous tokei run. Can be given a file path, or "stdin" to
read from stdin.
-o, --output
标签:CLI, Homebrew安装, Rust, SOC Prime, Tokei, WiFi技术, 二进制发布, 云安全监控, 代码分析, 代码统计, 代码行数, 凭证管理, 可视化界面, 开发工具, 开发效率, 开源工具, 统计工具, 编程语言分析, 网络可观测性, 网络流量审计, 请求拦截, 通知系统, 静态分析