Installation of cloc
Now let’s see how we can install the cloc on different operating systems. Use one of the following commands according to your operating system:
For Debian, Ubuntu:
sudo apt install cloc
For Red Hat, Fedora:
sudo yum install cloc
Fedora 22 or later:
sudo dnf install cloc
For Arch:
sudo pacman -S cloc
For Gentoo :
sudo emerge -av dev-util/cloc
For Alpine Linux
sudo apk add cloc
For OpenBSD
doas pkg_add cloc
For FreeBSD:
sudo pkg install cloc
For macOS with MacPorts:
sudo port install cloc
For macOS with Homebrew:
brew install cloc
For Windows with Chocolatey:
choco install cloc
For Windows with Scoop:
scoop install cloc
To install the cloc using npm use the following command:
npm install -g cloc
Now we have installed the cloc on the system. Let’s see how to use the cloc. The general syntax of using cloc is as follows
cloc [options] <FILE|DIR> ...
Now let’s see understand by one example. We have one source file written in CPP and contains the following code:
// hello.C #include <iostream> int main () { std::cout << "hello" << std::endl; // comment 1 std::cout << "again" << std::endl; /* comment 2 */ }
Now let’s use the cloc to count the line
As we can see, the cloc has correctly counted the comments and code lines.
CLOC – Count number of lines of code in file
cloc is a command-line-based tool. It counts the blank lines, comment lines, actual code lines written in many programming languages. cloc is completely written in the Perl language, and it has no external dependencies. cloc can run on many operating systems like Linux, macOS, Windows, OpenBSD and many more.