Table of Contents

About

The wc command is a filter that prints on one line sequentially the number of:

from:

  • files
  • or from an input stream when:
    • no FILE is specified
    • or the file argument - is specified

Example

With Standard Input from a pipeline

  • with the file hello.txt. You can create it with the below command in bash that uses echo gnu.
/bin/echo -e 'Hello\nWorld' > hello.txt
# -e takes the sequence character \n has an end of line
Hello
World

cat hello.txt | wc # read from the input stream created by cat
2       2      12

With Manual Standard Input (Copy / Paste )

wc -
  • Manually:
    • Type your text
    • or copy/paste:
      • in bash, right click to paste,
      • in dos, ctrl+v
  • Then send and end of file character
    • in bash: Ctrl+D
    • in dos: Ctrl+Z (^Z) on Windows

Example when copy/pasting

The wc command is a filter that prints on one line sequentially the number of:

newlines (lines),
words,
and characters

5      20     120 -

With a file as argument

When using a file name as argument

wc hello.txt # transform hello.txt as an input stream and read 
2  2 12 hello.txt

With a glob pattern that select files as argument

with a a glob pattern that select all files that begins with hello

wc hello*
2  2 12 hello.txt
 1  2 12 helloIn.txt
 1  2 12 helloOut.txt
 4  6 36 total

Syntax

wc [OPTION]... [FILE]...

where option can be

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