How to do it...

The wc command supports options to count the number of lines, words, and characters:

  1. Count the number of lines:
      $ wc -l file
  1. To use stdin as input, use this command:
      $ cat file | wc -l
  1. Count the number of words:
      $ wc -w file
      $ cat file | wc -w
  1. Count the number of characters:
      $ wc -c file
      $ cat file | wc -c

 To count the characters in a text string, use this command:

      echo -n 1234 | wc -c
      4

 Here, -n deletes the final newline character.

  1. To print the number of lines, words, and characters, execute wc without any options:
      $ wc file
      1435   15763  112200

Those are the number of lines, words, and characters.

  1. Print the length of the longest line in a file with the -L option:
      $ wc file -L
      205