{"id":13414178,"url":"https://github.com/cgag/loc","last_synced_at":"2025-10-03T14:55:15.683Z","repository":{"id":9564927,"uuid":"62609239","full_name":"cgag/loc","owner":"cgag","description":"Count lines of code quickly.","archived":false,"fork":false,"pushed_at":"2024-04-21T20:06:03.000Z","size":396,"stargazers_count":2375,"open_issues_count":58,"forks_count":126,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-04-28T11:52:23.552Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cgag.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-05T05:47:39.000Z","updated_at":"2025-04-25T17:29:27.000Z","dependencies_parsed_at":"2024-06-19T06:15:16.841Z","dependency_job_id":"db7c5049-4609-4f7e-99d2-fa9e7dd087d3","html_url":"https://github.com/cgag/loc","commit_stats":{"total_commits":207,"total_committers":50,"mean_commits":4.14,"dds":0.3188405797101449,"last_synced_commit":"1e0c7f434ddfd51439e1d4eb126f31b7a04229d9"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgag%2Floc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgag%2Floc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgag%2Floc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgag%2Floc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cgag","download_url":"https://codeload.github.com/cgag/loc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254020659,"owners_count":22000757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T21:00:16.091Z","updated_at":"2025-10-03T14:55:10.203Z","avatar_url":"https://github.com/cgag.png","language":"Rust","funding_links":[],"categories":["Misc","Rust","Development","Tools","Code","Other"],"sub_categories":["Time Series","Rust","Cloc"],"readme":"2019-10-07: I really haven't been on top of accepting pull requests or looking at issues, you guy should definitely look at [SCC](https://github.com/boyter/scc).  It's faster and more accurate than this, and Boyter has written a great series of blog posts detailing how it got this way:  [https://boyter.org/posts/sloc-cloc-code/](https://boyter.org/posts/sloc-cloc-code/)\n\n2018-03-08:\nI saw a bunch of stars pop up and thought I should mention that tokei is smarter and more accurate so please give that a look and see if there are any wild discrepancies (mostly for your benefit but please let me know if so).  Tokei is linked below but it's also rust so `cargo install tokei` is all you need.  Also these benchmarks are quite old. I doubt cloc has changed but tokei probably has. \n\n`loc` is a tool for counting lines of code. It's a rust implementation of [cloc](http://cloc.sourceforge.net/), but it's more than 100x faster. There's another rust code counting tool called [tokei](https://github.com/Aaronepower/tokei), loc is ~2-10x faster than tokei, depending on how many files are being counted.\n\nI can count my 400k file `src` directory (thanks npm) in just under 7 seconds with loc, in a 1m14s with tokei, and I'm not even willing to try with cloc.\n\nCounting just the dragonflybsd codebase (~9 million lines):\n  - loc: 1.09 seconds\n  - tokei: 5.3 seconds\n  - cloc: 1 minute, 50 seconds\n\n### Installation\n\nThere are binaries available on the [releases page](https://github.com/cgag/loc/releases), thanks to the wonderful rust-everywhere project and travisci. For anyone familiar with Rust there's `cargo install loc`.\nIf you want to install Rust/Cargo, this is probably the easiest way: [https://www.rustup.rs/](https://www.rustup.rs/).\n\n#### Windows\n\n`loc` should now compile on Windows, but you can also run it under Windows using linux emulation:\n\n\u003e You can run `loc` on Windows 10 Anniversary Update build 14393 or later using the [Windows Subsystem for Linux](https://msdn.microsoft.com/de-de/commandline/wsl/install_guide?f=255\u0026MSPPError=-2147217396). Simply download the Linux distribution from the [releases page](https://github.com/cgag/loc/releases), and run it in `bash` using a WSL-compatible path (e.g. `/mnt/c/Users/Foo/Repo/` instead of `C:\\Users\\Foo\\Repo`).\n\n### Usage\n\nBy default, `loc` will count lines of code in a target directory:\n\n``` shell\n$ loc\n--------------------------------------------------------------------------------\n Language             Files        Lines        Blank      Comment         Code\n--------------------------------------------------------------------------------\n Lua                      2       387088        24193       193544       169351\n Rust                     4         1172          111           31         1030\n C                        4          700           75          155          470\n Markdown                 2          249           39            0          210\n Bourne Shell             4          228           41           27          160\n Ada                      2           53           12            9           32\n Toml                     1           26            4            2           20\n Gherkin                  1           12            2            2            8\n OCaml                    1           13            4            6            3\n Ruby                     1            4            0            2            2\n Handlebars               1            4            0            2            2\n--------------------------------------------------------------------------------\n Total                   23       389549        24481       193780       171288\n--------------------------------------------------------------------------------\n\n```\n\nYou can also pass one or many targets for it to inspect\n\n``` shell\n$ loc ci benches\n--------------------------------------------------------------------------------\n Language             Files        Lines        Blank      Comment         Code\n--------------------------------------------------------------------------------\n Bourne Shell             4          228           41           27          160\n Rust                     1           17            4            0           13\n--------------------------------------------------------------------------------\n Total                    5          245           45           27          173\n--------------------------------------------------------------------------------\n```\n\nTo see stats for *each file* parsed, pass the `--files` flag:\n\n```sh\n$ loc --files src\n--------------------------------------------------------------------------------\n Language             Files        Lines        Blank      Comment         Code\n--------------------------------------------------------------------------------\n--------------------------------------------------------------------------------\n Rust                     2         1028           88           29          911\n--------------------------------------------------------------------------------\n|src/lib.rs                         677           54           19          604\n|src/main.rs                        351           34           10          307\n```\n\nBy default, the columns will be sorted by `Code` counted in descending order. You can select a different column to sort\nusing the `--sort` flag:\n\n``` shell\n$ loc --files --sort Comment ci\n--------------------------------------------------------------------------------\n Language             Files        Lines        Blank      Comment         Code\n--------------------------------------------------------------------------------\n--------------------------------------------------------------------------------\n Bourne Shell             4          228           41           27          160\n--------------------------------------------------------------------------------\n|ci/before_deploy.sh                 68           15           13           40\n|ci/install.sh                       60           13            6           41\n|ci/script.sh                        41            8            8           25\n|ci/utils.sh                         59            5            0           54\n\n```\n\n`loc` can also be called with regexes to match and/or exclude files.\n\n``` shell\n$ loc --include 'count'\n--------------------------------------------------------------------------------\n Language             Files        Lines        Blank      Comment         Code\n--------------------------------------------------------------------------------\n Rust                     2          144           23            2          119\n--------------------------------------------------------------------------------\n Total                    2          144           23            2          119\n```\n\n``` shell\nloc --exclude 'sh$'\n--------------------------------------------------------------------------------\n Language             Files        Lines        Blank      Comment         Code\n--------------------------------------------------------------------------------\n Lua                      2       387088        24193       193544       169351\n Rust                     4         1172          111           31         1030\n C                        4          700           75          155          470\n Markdown                 2          275           38            0          237\n Ada                      2           53           12            9           32\n Toml                     1           26            4            2           20\n Gherkin                  1           12            2            2            8\n OCaml                    1           13            4            6            3\n Handlebars               1            4            0            2            2\n Ruby                     1            4            0            2            2\n--------------------------------------------------------------------------------\n Total                   19       389347        24439       193753       171155\n--------------------------------------------------------------------------------\n```\n\n\n### Known Issues\nFortran has a rule that comments must start with the first character of a line. I only check if it's the first non-whitespace character of a line. I don't know\nhow often this is a problem in real code.  I would think not often.\n\nComments inside string literals: You can get incorrect counts if your code has something like this:\n\n```\nx = \"/* I haven't slept \\\nfor 10 days \\\nbecause that would be too long \\\n*/\";\n```\n\nloc counts the first line and last lines correctly as code, but the middle\nlines will be incorrectly counted as comments.\n\nIgnored and hidden files:\n\nBy default, loc respects .gitignore/.ignore files, and ignores hidden files and directories.  You can count disregard\nignore files with `loc -u`, and include hidden files/dirs with `loc -uu`.\n\n### Supported Languages\n\n- ActionScript\n- Ada\n- Agda\n- AmbientTalk\n- ASP\n- ASP.NET\n- Assembly\n- Autoconf\n- Awk\n- Batch\n- Bourne Shell\n- C\n- C Shell\n- C/C++ Header\n- C#\n- C++\n- Clojure\n- CoffeeScript\n- ColdFusion\n- ColdFusionScript\n- Coq\n- CSS\n- CUDA\n- CUDA Header\n- D\n- Dart\n- DeviceTree\n- Erlang\n- Forth\n- FORTRAN Legacy\n- FORTRAN Modern\n- F# (Fsharp)\n- GLSL\n- Go\n- Groovy\n- Handlebars\n- Haskell\n- Hex\n- HTML\n- Idris\n- INI\n- Intel Hex\n- Isabelle\n- Jai\n- Java\n- JavaScript\n- JSON\n- Jsx\n- Julia\n- Kotlin\n- Lean\n- Less\n- LinkerScript\n- Lisp\n- Lua\n- Make\n- Makefile\n- Markdown\n- Mustache\n- Nim\n- Nix\n- Objective-C\n- Objective-C++\n- OCaml\n- OpenCL\n- Oz\n- Pascal\n- Perl\n- PHP\n- Plain Text\n- Polly\n- PowerShell\n- Prolog\n- Protobuf\n- Pyret\n- Python\n- Qcl\n- QML\n- R\n- Razor\n- reStructuredText\n- Ruby\n- RubyHtml\n- Rust\n- SaltStack\n- Sass\n- Scala\n- SML\n- Solidity\n- SQL\n- Stylus\n- Swift\n- Tcl\n- Terraform\n- TeX\n- Toml\n- TypeScript\n- Tsx\n- UnrealScript\n- VimL\n- Wolfram\n- XML\n- Yacc\n- YAML\n- Zig\n- Z Shell\n\n## Attributions\n\nThis project contains code from [Tokei](https://github.com/Aaronepower/tokei) by [Aaronepower](https://github.com/Aaronepower) and [ripgrep](https://github.com/BurntSushi/ripgrep) by [BurntSushi](https://github.com/BurntSushi).\n\n### Contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgag%2Floc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcgag%2Floc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgag%2Floc/lists"}