How to Install and Use tokei in Linux for Blazing-Fast Code Statistics and Line Counting

Understanding the composition and scale of a software codebase—such as knowing how many lines of Rust, Python, TypeScript, or C++ make up a repository, and distinguishing actual logic from blank lines and comments—is essential during code audits and technical planning. Traditional tools like cloc (Count Lines of Code) are comprehensive but notoriously slow when parsing large multi-gigabyte repositories. tokei is an ultra-fast, multi-threaded code statistics program written in Rust that can analyze hundreds of thousands of files across over 150 programming languages in mere milliseconds.

Installing tokei on Linux Distributions

tokei is packaged across standard package repositories and available via cargo:

  • Arch Linux: Install directly from official repositories:
    sudo pacman -S tokei
  • Fedora:
    sudo dnf install tokei
  • Cargo (Universal): Install from crates.io:
    cargo install tokei
  • Homebrew:
    brew install tokei

Running Basic Code Statistics on a Project

Navigate to any source code repository in your terminal and invoke tokei without arguments:

  1. Type tokei and press Enter.
  2. tokei scans all nested directories, automatically respecting .gitignore rules to exclude compiled assets, vendor libraries, and build caches.
  3. It prints a clean, colour-coded terminal table summarizing:
    • Language: Identified programming and markup languages.
    • Files: Total file count per language.
    • Lines: Total line volume.
    • Code: Pure executable code lines.
    • Comments: Documented comment lines.
    • Blanks: Empty formatting lines.

Advanced Filtering and Sorting Options

Tailor your analysis for specific auditing requirements:

  • Sorting by Code Lines: Rank dominant languages by logic volume:
    tokei --sort code
  • Outputting Clean JSON or YAML: Export metrics for continuous integration (CI) pipelines or dashboard dashboards:
    tokei --output json > metrics.json
  • Inspecting Individual Files: Inspect breakdown per individual file within a specific language:
    tokei --files

With its unbeatable speed and automatic ignore integration, tokei is an indispensable terminal utility for developers managing and auditing complex Linux codebases.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.