Linux Commands: How to use wc

The wc command is used to count newlines, words, or bytes in a given file. Used with a pipe it can also be untilised for general counting operations. The following sections give a few examples of how it can be used.

To count the number of bytes in a file:

$ cat 02-Test.m3u | wc -c

To find the length of the longest line in a file. NB calling wc with the name of a file supplied results in output which contains both the answer and the file name., whilst piping to wc results only in the answer.

$ wc -L 02-Test.m3u
71 02-Test.m3u

$ cat 02-Test.m3u | wc -L
71

To count the number of files plus directories at the current location

$ ls -1 | wc -l