wc

Powerful utility for counting words, lines, and characters in text files. Whether you’re analyzing logs, reading large datasets, or just checking the size of your scripts, wc gives a quick summary. It can take one or more files as input or read directly from user input if no file is mentioned.

  • Line count – number of lines (each line ends with a newline character).
  • Word count – total number of words (words are separated by spaces, tabs, or newlines).
  • Byte count – total number of bytes (which may differ from characters in some cases).
  • Filename – name of the file that was processed.
wc go.sum
4  12 394 go.sum

here is:
4: Number of Lines
12: Number of Words
394: Number of bytes

Options:

  • -c, –bytes
    • print the byte counts
  • -m, –chars
    • print the character counts
  • -l, –lines
    • print the newline counts
  • -L, –max-line-length
    • print the maximum display width
  • -w, –words
    • print the word counts

Checking more than one file

wc file1 file2 file3


➜ wc go.sum go.mod package.json
   4   12  394 go.sum
   5    9   83 go.mod
  26   53  587 package.json
  35   74 1064 total

Useful applications of wc command

To count all files and folders in directory

❯ ls content/
about  about_me  blog  docs  _index.md

➜ ls content | wc -l
5