Auditing software codebases and measuring project scale requires inspecting more than raw file counts or directory disk footprints. While traditional tools like wc -l can count raw lines of text, they fail to distinguish between functional program code, comment documentation, and blank whitespace. The tokei command Linux utility provides a blazing-fast, accurate code statistics engine capable of parsing millions of lines of source code across hundreds of programming languages in milliseconds.
What Is the tokei Command in Linux?
Written in Rust, tokei (Japanese for “clock” or “statistics”) is an open-source command-line tool dedicated to code analysis. It recognizes over 150 programming languages, intelligently ignores nested comment blocks and embedded string literals, filters out non-code assets, and presents structured tabular breakdowns showing total files, blank lines, comments, and actual lines of code (LoC).
How to Install tokei on Linux
Tokei is distributed as native binary packages across multiple Linux repositories and package managers.
Installing on Arch Linux
On Arch Linux, install Tokei directly from the official extra repository:
sudo pacman -S tokei
Installing on Debian, Ubuntu, and Linux Mint
You can download the pre-compiled binary release from the official GitHub releases page or install it using Cargo:
# Download the latest pre-compiled binary
curl -LO https://github.com/XAMPPRocky/tokei/releases/latest/download/tokei-x86_64-unknown-linux-musl.tar.gz
tar -xzf tokei-*.tar.gz
sudo mv tokei /usr/local/bin/
Installing on Fedora
On Fedora, install Tokei via the official DNF repositories:
sudo dnf install tokei
Installing via Cargo
If you maintain a local Rust development environment, build Tokei directly with Cargo:
cargo install tokei
Running Your First Code Statistics Scan
To inspect a codebase, pass the path of your project repository or execute tokei directly inside the project root directory:
tokei
Tokei immediately scans the directory hierarchy and outputs a formatted terminal table containing:
- Language: Identified programming and markup languages (e.g., Rust, Python, JavaScript, CSS, HTML, Markdown).
- Files: Total individual source files identified for that language.
- Lines: Gross total lines of text.
- Code: Net functional lines of executable source code.
- Comments: Documentation lines, single-line comments, and multi-line docstrings.
- Blanks: Blank lines and whitespace formatting.
Inspecting Individual Files Within Languages
By default, Tokei aggregates metrics by language. If you need to pinpoint specific files that account for the bulk of a project’s size, supply the --files flag:
tokei --files
This expands each language section to display an itemised list of individual file paths, revealing oversized source files that may require refactoring.
Excluding Build Artifacts and Vendor Directories
Modern software repositories frequently contain massive dependency folders (such as node_modules, target/, venv/, or vendor/) that distort code counts. Tokei automatically respects .gitignore rules by default. To explicitly exclude additional directories or file patterns, use the -e (or --exclude) flag:
tokei -e target -e node_modules -e "*.min.js"
Filtering by Specific Programming Languages
If you are auditing a multi-stack project but only care about backend logic, you can filter Tokei’s scope by specifying language names with the -t (or --type) flag:
# Scan only Python and SQL files
tokei -t=Python,SQL
# Scan only Rust source files
tokei -t=Rust
Exporting Results as JSON or YAML
For continuous integration (CI) pipelines, repository audits, or generating badges for documentation, Tokei can format output as machine-readable data using the -o flag:
# Output comprehensive JSON metrics
tokei -o json > code_metrics.json
# Output clean YAML formatting
tokei -o yaml