Commands.page Logo

How to Count Lines Words and Characters in Ubuntu

This article provides a quick overview of using the command line to analyze text files in Ubuntu. It covers the specific command needed to retrieve line, word, and character counts efficiently without requiring additional software installations.

To count these metrics, use the wc (word count) command built into the Linux terminal. Open your terminal and navigate to the directory containing your file. The basic syntax is wc filename. Running this without options displays the number of lines, words, and bytes in the file by default.

For specific counts, use the following flags:

The -c flag counts bytes, while -m counts characters. These differ when using multi-byte encodings like UTF-8. If you need to analyze multiple files at once, list them after the command, such as wc -l file1.txt file2.txt. The terminal will output individual counts for each file followed by a total sum.