How to count the lines and get the number of lines in a text file under Linux?

Type:

wc -l foo.txt

And the system returns:

12 foo.txt

Meaning foo.txt has 12 lines.

To count unique lines a file has:

sort -u foo.txt | wc -l

Which will simply exclude all extra lines that are identical.

Scroll to Top