--- title: tokei β€” Code Line Counter date: 2026-01-19 time: 12:00 model: admin category: programs author_type: human summary: Code statistics tool that quickly counts lines by language, including code, comments, and blanks tags: program, Modern CLI Tools, tokei --- **πŸ’¬ "tokei command"** tokei is a tool that **counts lines of code by language** across a codebase. It tells you how much code you have per language, and how many of those lines are code, comments, and blanks. Written in Rust it counts even huge repositories in an instant, and can filter to only git-tracked or hidden files. Use it to gauge project size and plan refactors. - **Concept**: Scan a folder and report per-language code, comment, and blank line counts. - **Features**: Per-language line counts, code/comment/blank split, file counts, sorting, and JSON output. - **Strength**: Counts even hundred-thousand-line projects in under a second, as a table or JSON. - **Use when**: Gauging project size, checking technical debt, or comparing language mixes. ## Basic Usage tokei counts automatically when you point it at a folder. No config needed. ### 1. Basic count Scan the current folder for per-language stats. ``` tokei # current folder tokei src # a specific folder ``` ### 2. Filtering Include hidden files or skip gitignore. ``` tokei --hidden # include hidden files tokei --no-ignore # ignore .gitignore tokei --files # count files only ``` ### 3. Sorting and output Sort by most code or emit JSON. ``` tokei --sort code # sort by code lines tokei -o json | jq '.["Rust"].code' ``` ## Installation & Download tokei installs via cargo, a package manager, or a release binary. | Environment | Command | | --- | --- | | cargo | cargo install tokei | | Ubuntu/Debian (if packaged) | sudo apt install tokei | | Arch | sudo pacman -S tokei | | Release binary | github.com/XAMPPRocky/tokei/releases | Verify with `tokei --version`. Count with `tokei folder` by passing a path. ## Common Options | Command / Key | Description | | --- | --- | | --sort code | Sort by code line count | | --files | Count only files | | --hidden | Include hidden files | | --no-ignore | Ignore .gitignore rules and count everything | | -o json | Output JSON for piping to other tools | ## 3 Essential Command Combinations - `tokei .` β€” Count lines per language in the project - `tokei --sort code | head` β€” See the languages with the most code - `tokei -o json | jq 'keys'` β€” Extract the language list as JSON **πŸ’¬ "Using tokei on a real server"** A step-by-step look at gauging project size. ### Step 1 Β· Count the project Scan the project folder. ``` tokei ~/workspace/site ``` ### Step 2 Β· Sort by language See which languages dominate. ``` tokei --sort code ~/workspace/site ``` ### Step 3 Β· Save results Store the stats as JSON. ``` tokei -o json ~/workspace/site > loc.json ``` ## How it is used in practice ### 1. Gauge project size **Situation** β€” Check the size of a newly joined project. ``` tokei --sort code . ``` **Result** β€” Per-language code, comment, and blank counts appear as a table. **Point** β€” Set refactor priorities and estimate effort. ### 2. Compare language mixes **Situation** β€” Compare language balance across projects. ``` for d in api web; do echo $d; tokei --sort code $d | head -3; done ``` **Result** β€” Compare top languages per project. **Point** β€” Check for tech-stack skew or duplication. ## Caveats - Files listed in `.gitignore` are excluded by default (use `--no-ignore` to include them). - With `--no-ignore` on very large dependency folders, counting can slow down. - tokei counts lines onlyβ€”it does not judge code quality or complexity. --- Source (HTML): https://games.aidebatehub.com/programs/linux/modern/tokei.html This file is an auto-generated Markdown twin of the DevHub document.