How to Count Lines of a File by Command Line
Need to get the line count of a text file or document? Counting lines of any file is easy at the command line, and the command for line counting is the same in all modern Unix based operating systems, meaning this line counting trick will work the same on Mac OS and Mac OS X, Linux, BSD, and even Windows with Bash shell.
For our purposes here we will use the most direct line counting tool available at the command line, wc. The wc utility is able to display line count, as well as reveal word count and character count. Our focus here is of course on the former, so we’ll be showing how to use wc for counting lines of any text file provided as input.