Home » linux » Linux and Unix wc command tutorial with examples

Linux and Unix wc command tutorial with examples

“ wc ” command stands for “word count”.
“ wc “ command in Unix/Linux OS is used to calculate/find out and print the number of lines, number of words, number of character and byte of a file.

Syntax:
$ wc [option] [filename]

Example: There is a sample file file01.txt.

Type command on terminal…

The above command displays the output “ 3 11 44 “. Where 3 is a number of lines, 11 is the number of words and 44 is a number of character on a specified file “ file01.txt”.

Options of “wc” command are:

Sr NoOptionMeaning
1-l
used to print the number of lines in a file.
2-w
used to print the number of words in a file
3-c

used to print the number of character in a file.
4-Lused to print the length of longest line.

(-l) option: wc command with –l option is used to print the number of lines in a file. Type below command on terminal

The above command displays the output “3”. Where 3 is a number of lines on a specified file “ file01.txt”.

(-w) option: wc command with –w option is used to print the number of words in a file. Type below command on terminal…

The above command displays the output “ 11 “. Where 11 is the number of words in a specified file “file01.txt”.

(-c) option: wc command with –c option is used to print the number of character in a file. Type below command on terminal…

The above command displays the output “ 44 “. Where 44 is a number of character of words in a specified file “ file01.txt”.

Managed by MochaHost - Fast & Easy WordPress Hosting