How to count number of lines in a text file using Linux shell

Sometimes you need an easy way to count number of lines in a text file.
For example, how many lines in a .csv file.

wc -l somefilename.csv

You can also count number of characters in a file using “wc”:
wc -m somefilename.txt

Or number of words:
wc -w somefilename.txt

Explore the possiblities of “wc”:

# wc --help
Usage: wc [OPTION]... [FILE]...
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.
-c, --bytes print the byte counts
-m, --chars print the character counts
-l, --lines print the newline counts
-L, --max-line-length print the length of the longest line
-w, --words print the word counts
--help display this help and exit
--version output version information and exit

Report bugs to .

No Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: