← 返回命令列表

Linux command

tokei 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Count lines of code in the current directory

tokei

Count a specific directory

tokei [path/to/project]

Count multiple directories

tokei [path/to/project] [path/to/other]

Exclude directories or patterns

tokei -e [vendor] -e [node_modules]

Show files individually

tokei --files

Sort by a specific column

tokei -s [code]

Output as JSON

tokei -o json

Count only specific languages

tokei -t [Rust,Python]

Show supported languages

tokei --languages

Read from a previously saved JSON output

tokei [path/to/project] -i [stats.json]

说明

tokei counts lines of code quickly and accurately. It identifies languages by file extension, categorising lines as code, comments, or blank, and groups results by language. The tool is written in Rust with parallel file processing, making it capable of counting millions of lines in seconds. Results show a per-language breakdown with a grand total. Language detection supports over 150 languages with correct handling of multi-line comments, nested comments, and strings containing comment-like syntax. File filtering respects .gitignore and .ignore files by default, which excludes generated code and dependency directories. Additional patterns can be excluded with -e, or a .tokeignore file can be used with the same syntax as .gitignore. Individual file mode (--files) shows statistics per file rather than aggregated by language, useful for identifying verbose or generated files. Machine-readable output (JSON, YAML, CBOR) enables integration with other tools and CI/CD pipelines. A previous run's JSON output can be fed back in with --input to combine results across separate directory trees.

参数

-e, --exclude _PATTERN_
Ignore all files and directories matching the pattern. Uses gitignore syntax. Can be specified multiple times.
-t, --type _TYPES_
Filter output by language type, separated by a comma (e.g. Rust,Markdown).
-s, --sort _COLUMN_
Sort languages by column. Possible values: files, lines, blanks, code, comments. Default: alphabetical by language name.
-o, --output _FORMAT_
Output in a machine-readable format. Possible values: json, yaml, cbor.
-i, --input _FILE_
Read in the output of a previous tokei run and combine it with the current results. Pass a file path or "stdin" to read from stdin.
-f, --files
Print statistics for individual files instead of aggregating by language.
-l, --languages
Print a list of all supported languages and their file extensions.
--hidden
Count hidden files and directories (those beginning with a dot).
--no-ignore
Don't respect any ignore files (.gitignore, .ignore, etc.). 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 in parent directories.
--no-ignore-vcs
Don't respect VCS ignore files (.gitignore, .hgignore, etc.), including those in parent directories.
-c, --columns _NUM_
Set a strict column width for terminal output.
-v, --verbose
Increase log output level. Use up to three times (-vvv) for more detail.

FAQ

What is the tokei command used for?

tokei counts lines of code quickly and accurately. It identifies languages by file extension, categorising lines as code, comments, or blank, and groups results by language. The tool is written in Rust with parallel file processing, making it capable of counting millions of lines in seconds. Results show a per-language breakdown with a grand total. Language detection supports over 150 languages with correct handling of multi-line comments, nested comments, and strings containing comment-like syntax. File filtering respects .gitignore and .ignore files by default, which excludes generated code and dependency directories. Additional patterns can be excluded with -e, or a .tokeignore file can be used with the same syntax as .gitignore. Individual file mode (--files) shows statistics per file rather than aggregated by language, useful for identifying verbose or generated files. Machine-readable output (JSON, YAML, CBOR) enables integration with other tools and CI/CD pipelines. A previous run's JSON output can be fed back in with --input to combine results across separate directory trees.

How do I run a basic tokei example?

Run `tokei` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -e, --exclude _PATTERN_ do in tokei?

Ignore all files and directories matching the pattern. Uses gitignore syntax. Can be specified multiple times.