LinuxCommandLibrary

loc

counts lines of code quickly

TLDR

Count lines of code in the current directory
$ loc
copy
Count lines of code in a specific directory
$ loc [path/to/directory]
copy
Show per-file statistics
$ loc --files
copy
Exclude files matching a regex pattern
$ loc --exclude [test]
copy
Count only files matching a regex pattern
$ loc --include [\.rs$]
copy
Sort output by a specific column
$ loc --sort [code]
copy
Include files ignored by .gitignore
$ loc -u
copy
Include hidden files and directories as well
$ loc -uu
copy

SYNOPSIS

loc [options] [paths]

DESCRIPTION

loc counts lines of code quickly. It identifies programming languages and separates code, comments, and blank lines. By default, it respects .gitignore and .ignore files and skips hidden files and directories.
The tool is written in Rust for speed and can process large codebases significantly faster than alternatives like cloc.

PARAMETERS

PATHS

Directories or files to analyze. Defaults to the current directory.
--files
Display statistics for each individual file parsed.
--sort COLUMN
Sort results by the specified column (e.g., code, comment, lines, blank). Default is code in descending order.
--include REGEX
Count only files matching the specified regex pattern.
--exclude REGEX
Exclude files matching the specified regex pattern.
-u
Unrestricted mode. Disregard .gitignore and .ignore files. Use twice (-uu) to also include hidden files and directories.

CAVEATS

Results may differ from other line counters due to differing language detection heuristics and comment-parsing rules. The project is no longer actively maintained.

SEE ALSO

cloc(1), tokei(1), sloccount(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard