wc

print newline, word, and byte counts for each file

Syntax

wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F

Description

Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. With no FILE, or when FILE is -, read standard input.

Options

-c, --bytes
       print the byte counts

-m, --chars
       print the character counts

-l, --lines
       print the newline counts

--files0-from=F
       read input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input

-L, --max-line-length
       print the length of the longest line

-w, --words
       print the word counts

Example 1

Demonstrate wc command

[eleiss@eleiss ~]$ cat eleiss
Eleiss is an IT company based in Surat which provides Linux based solutions and training.
Solution: Desktop, Server, Network, Security
Training: Basic Linux, Shell Scripting, Unix Programming, Distributed Unix Programming.
[eleiss@eleiss ~]$ wc eleiss
  3  30 223 eleiss
[eleiss@eleiss ~]$

Here the output says that the file eleiss has 3 lines, 30 words and 223 characters in it.

Count and verify it. When you count characters, do not forget to consider spaces and new line characters too. :-)

Example 2

Demonstrate wc command without argument

[eleiss@eleiss ~]$ wc
She forgot to bring her raincoat and it started raining very hard. 
She got cold within few minutes.
      2      18     100
[eleiss@eleiss ~]$

When no argument is specified to the command, it takes data from standard input until Ctrl+d is pressed. The above output says there are total 2 lines, 18 words and a hundred characters.

Example 3

Count words, lines and characters individually with wc command.

[eleiss@eleiss ~]$ cat eleiss
Eleiss is an IT company based in Surat which provides Linux based solutions and training.
Solution: Desktop, Server, Network, Security
Training: Basic Linux, Shell Scripting, Unix Programming, Distributed Unix Programming.
[eleiss@eleiss ~]$ wc -l eleiss
3 eleiss
[eleiss@eleiss ~]$ wc -w eleiss
30 eleiss
[eleiss@eleiss ~]$ wc -c eleiss
223 eleiss
[eleiss@eleiss ~]$

There are individual switches available in order to calculate total number of words, lines and characters.


You may write to resources@eleiss.com for any Linux related queries.

advertisement