How to Count Number of File Lines in UNIX/Linux

You can follow below 2 methods of getting the lines count in the UNIX / Linux operating system. If you have any other method, please feel free to share it in the comment section.

Method 1

Using the wc command. You can also refer to this published article on wc, wc: Print newline, word, and byte counts for file.

wc -l [FILENAME]

Method 2

Using the vi editor. We would prefer to use the wc command because it’s fast and not much steps to execute. But, still, you can try to use this way if you comfortable with it.

Step 1: Open the file with the vi command

vi [FILENAME]

Step 2: Press SHIFT + : and type in set number. Now, press Enter.

Step 3: You will now see the line numbers from the screen editor. As below screenshot, the file contain 11 lines.

Note: If you are working on file which have thousand of lines, you can press SHIFT + gg to jump to the last line, so from there, you will get the number of the last line.

You May Also Like

Leave a Reply?