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.

Easy:

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 <bug-coreutils@gnu.org>.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

If you enjoyed this post, make sure you subscribe to our RSS Feed! Or if you prefer, you can Follow us on Twitter instead.