Skip to content

cloc: Count Lines of Code in Many Programming Languages

Updated 2 min read

Updated: 28 September 2026 · Applies to: cloc 1.98 to 2.10 on Ubuntu 24.04 and 26.04, Debian 13, AlmaLinux and Rocky Linux 9 and 10 (EPEL)

cloc ("count lines of code") counts the lines in a project and splits them into code, comments and blank lines, per programming language. It is useful for estimating the size of a code base before a migration or audit, or for comparing two versions. It understands several hundred languages and can read Git repositories and archives directly.

Install cloc

apt install cloc                                  # Ubuntu, Debian
dnf install epel-release && dnf install cloc       # AlmaLinux, Rocky Linux

EPEL has the current version 2.10; Ubuntu 24.04 has 1.98 and Debian 13 has 2.04. The newest release is always on the project's GitHub page as a single Perl script.

Count a project

cloc /var/www/myapp

The result is a table with one line per language: number of files, blank lines, comment lines and code lines, with a total at the end.

Useful options

cloc --exclude-dir=vendor,node_modules,.git /var/www/myapp   # skip dependencies
cloc --by-file /var/www/myapp                                 # per file instead of per language
cloc --include-lang=PHP,JavaScript /var/www/myapp             # only some languages
cloc project.tar.gz                                           # count inside an archive
cloc --vcs=git /path/to/repo                                  # only files tracked by Git

Compare two versions

cloc --diff myapp-1.0/ myapp-2.0/

This shows lines added, removed, modified and unchanged per language.

Output for reports

cloc --csv --quiet /var/www/myapp > loc.csv
cloc --json /var/www/myapp > loc.json

Tips

  • Always exclude third-party folders such as vendor and node_modules, or they will dominate the result.
  • Minified or generated files inflate the counts; exclude them with --not-match-f='\.min\.js$'.

Official documentation: cloc on GitHub.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket