Count lines, words and characters from a file in Linux

wc is a Linux utility that allows you to get details about files – like how many lines, words etc a file has.

The most useful options of the command are:

-w, --words	prints the number of worlds
-l, --lines	prints the number of lines
-m, --chars	prints the number of characters

To count the number of worlds in a file:

# wc -w textfile.txt
root@www [/]# wc -w textfile.txt
8531 textfile.txt
root@www [/]#

To count the number of lines in a file:

# wc -l textfile.txt
root@web [/]# wc -l textfile.txt
198 textfile.txt
root@web [/]#

To count the number of characters in a file:

# wc -m textfile.txt
root@web [/]# wc -m textfile.txt
57678 textfile.txt
root@web [/]#

For more information about this command run #man wc

References:
wc man file

Leave a Reply