tokei Count lines of code

Version 15.0.0 · source

Start here

tokei
Count the current directory
tokei <path>...
Count given paths
tokei -f
One line per file
tokei -s code
Sort by code lines
tokei -t=<lang>
Only one language
tokei -e <glob>
Skip matching paths
tokei -o json
Machine-readable output
tokei -l
List known languages

Concepts

  1. Walk paths ignore files applied
  2. Match language by extension
  3. Split lines code / comments / blanks
What a run does

Counting

tokei
Table for the current directory
tokei <dir> <dir>
Count several paths together
tokei -f
Show every file
tokei -s <key>
Sort rows by files, lines, blanks, code or comments
tokei -s code -f
Biggest files by code lines
tokei --hidden
Include hidden files
tokei -c <n>
Fixed output width in columns
tokei -l
List supported languages and extensions
tokei -v
Log unknown extensions (-vv for more)
tokei -V
Print the version

Filtering

tokei -t=<lang>,<lang>
Only these languages
tokei -t=Rust,Markdown
Example: Rust and Markdown only
tokei -e <pattern>
Exclude files or dirs, gitignore syntax
tokei -e '*.d' -e <dir>
Repeat -e for several patterns
tokei --no-ignore
Count everything, ignore all ignore files
tokei --no-ignore-vcs
Skip only .gitignore/.hgignore
tokei --no-ignore-dot
Skip .ignore and .tokeignore
tokei --no-ignore-parent
Skip ignore files in parent dirs

Output and config

tokei -o json
Print JSON instead of a table
tokei -o yaml
Print YAML
tokei -o cbor
Print CBOR (binary)
tokei -o json > stats.json
Save a run for later
tokei -i stats.json
Load a saved run instead of scanning
tokei -i stdin
Read a saved run from a pipe
.tokeignore
Per-project exclude list, gitignore syntax
tokei.toml / .tokeirc
Default options; read from cwd, home, config dir
Install
Where Command
Cargo cargo install tokei
Homebrew brew install tokei
Arch pacman -S tokei
Fedora sudo dnf install tokei
Windows winget install XAMPPRocky.tokei

Recipes

Source only, biggest files first
tokei -f -s code -t=Rust src
Compare two points in history
tokei -o json > now.jsongit stash -q && git checkout -q <rev>tokei -o json > then.jsongit checkout -q - && git stash pop -q
Total code lines in a script
tokei -o json | jq '.Total.code'
Ignore tests and vendored code
printf 'vendor/\n*_test.go\n' >> .tokeignoretokei