Hosting Tips & Deals Linux Server Administration Tips

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


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.

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Shoot me a message.