How to count lines in a file on Linux?

Use wc :

  • wc -l <filename>

This will output the number of lines in <filename>

  • wc -l  < /dir/file.txt
  • 56789

You can also pipe the data to wc as well:

  • cat /dir/file.txt | wc -l
  • 56789

You can also see the number of lines in a directory in detail.

  • wc -l *
  • 256 192.168.86.0_24.txt
  • 256 192.168.87.0_24.txt
  • 256 192.168.99.0_24.txt
  • 768 total
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s