LinuxCommandLibrary

tokei

Count lines of code by language

TLDR

Display a report for the code in a directory and all subdirectories

$ tokei [path/to/directory]
copy

Display a report for a directory excluding .min.js files
$ tokei [path/to/directory] [[-e|--exclude]] [*.min.js]
copy

Display statistics for individual files in a directory
$ tokei [path/to/directory] [[-f|--files]]
copy

Display a report for all files of type Rust and Markdown
$ tokei [path/to/directory] [[-t|--type]] [Rust],[Markdown]
copy

SYNOPSIS

tokei [OPTIONS] [PATH...]
tokei diff [OPTIONS] [REF1] [REF2]

PARAMETERS

-l, --languages LANG...
    Filter results to include only specified programming languages.

-e, --exclude EXCLUDE...
    Exclude files or directories matching the given patterns.

-f, --files FILES...
    Only count statistics for the specified file paths.

-t, --type TYPE...
    Filter statistics by line type: code, comment, or blank.

-o, --output FORMAT
    Specify the output format (e.g., json, yaml, csv, markdown, plain).

-s, --sort SORT_ORDER
    Sort the output by a specific column or order (e.g., files, lines, name).

--hidden
    Include hidden files and directories in the analysis.

--no-ignore
    Do not respect .gitignore files.

--no-ignore-vcs
    Do not respect version control system (VCS) ignore files (e.g., .git/info/exclude).

--git
    Force tokei to only count files tracked by Git.

--color WHEN
    Control color output (e.g., always, auto, never).

-v, --verbose
    Enable verbose output, showing more details during processing.

-h, --help
    Display help message and exit.

--version
    Display version information and exit.

DESCRIPTION

tokei is a highly efficient and versatile command-line program, written in Rust, designed for quickly counting lines of code, comments, blank lines, and files across a multitude of programming languages.

It offers detailed statistics for over 150 languages, providing insights into the size and composition of a codebase. Users can generate reports in various formats, including plain text, JSON, YAML, CSV, and Markdown, facilitating integration with other tools or documentation.

tokei supports advanced filtering to include or exclude specific files, directories, or languages, and can even analyze code changes between Git revisions. Its multi-threaded architecture ensures exceptional speed, making it an ideal choice for analyzing large-scale projects where performance is crucial. It helps developers, project managers, and quality assurance teams gain a comprehensive overview of their software projects.

CAVEATS

tokei is not a standard pre-installed Linux command; it needs to be installed separately, typically via a package manager (like cargo, brew, or specific distribution packages) or by compiling from source.

While highly optimized, performance can still be influenced by extremely large codebases on systems with limited resources, especially when parsing numerous files with complex language structures. It may also occasionally misidentify or lack support for very obscure or highly domain-specific language dialects.

THE 'DIFF' SUBCOMMAND

The tokei diff subcommand allows users to analyze the differences in lines of code, comments, and blank lines between two Git revisions or branches. This is particularly useful for tracking codebase evolution, assessing the impact of changes, or reviewing pull requests. It can compare the current working directory with a specific commit, or two different commits within the repository.

Usage examples include tokei diff HEAD~1 HEAD to see changes from the previous commit, or tokei diff main develop to compare two branches.

HISTORY

tokei was created by XAMPPRocky and first released around 2018. It was developed in Rust with a primary focus on speed and accuracy, aiming to be a faster and more feature-rich alternative to existing code counters like cloc. Its multi-threaded design and broad language support quickly contributed to its popularity among developers. Development is ongoing, with regular updates introducing new features, language support, and performance improvements.

SEE ALSO

cloc(1), scc(1), git-diff(1)

Copied to clipboard