Linux command
loc 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Count lines of code in the current directory
loc
Count lines of code in a specific directory
loc [path/to/directory]
Show per-file statistics
loc --files
Exclude files matching a regex pattern
loc --exclude [test]
Count only files matching a regex pattern
loc --include [\.rs$]
Sort output by a specific column
loc --sort [code]
Include files ignored by .gitignore
loc -u
Include hidden files and directories as well
loc -uu
说明
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.
参数
- --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.
FAQ
What is the loc command used for?
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.
How do I run a basic loc example?
Run `loc` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --files do in loc?
Display statistics for each individual file parsed.