Count Lines of Code with CLOC

LinuxLinuxBeginner
Practice Now

Introduction

CLOC (Count Lines of Code) is a command-line tool that analyzes the files in a directory and counts the number of lines of code, comments, and blank lines in a wide variety of programming languages. It's an invaluable resource for developers seeking to understand the composition of their projects, measure productivity, or estimate project complexity.

cloc

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux/PackagesandSoftwaresGroup -.-> linux/software("`Linux Software`") subgraph Lab Skills linux/software -.-> lab-273383{{"`Count Lines of Code with CLOC`"}} end

Analyzing Your Project With CLOC

To use cloc, simply point it to a directory or file, and it will output a detailed report. The basic syntax is: cloc [options] <file/directory>.

For example, the Flask project is in the ~/project directory, so to count the lines of code, you can open the terminal ( ① or ② in the figure ) in the environment and enter the following command:

cloc .

This command provide a breakdown of the number of files, blank lines, comment lines, and lines of code for each programming language found.

cloc

Summary

cloc is a powerful tool for software developers, project managers, and code auditors to quantify the size and complexity of codebases. By mastering its base and advanced usages, you can gain valuable insights into your projects, track productivity, and make informed decisions about your code's architecture and maintenance requirements.

Other Linux Tutorials you may like