How to count number of lines in Linux file

In this article, we will see how to count number of lines in Linux file.

In this article, we are going to see three methods to find out numbers of lines in Linux file.

1. Using wc command.
2. Using cat command.
3. Using awk command.

Count number of lines in Linux file

1. Using wc command we can get number of lines and file name in Linux.

wc -l barmaninstallation.txt

How to count number of lines in Linux file

To get only number of lines without file name in Linux:

wc -l barmaninstallation.txt| cut -d\ -f 1

2. Find number of lines in a Linux file using cat with wc commands.

cat barmaninstallation.txt | wc -l

3. Find number of lines in Linux file using awk command. It lists empty lines as well.

awk '{c++};END{print c}' < barmaninstallation.txt

The above three are most used methods to find the number of lines in Linux file.