Count Lines in a File in Linux

Count Lines in a File in Linux

There are various commands in Linux system that helps to process files. Sometimes we may need to count lines in a file. It can help to determine how large a given file is. This tutorial provides example how to count lines in a file in Linux.

Create a new file for testing:

printf "Line1\nLine2\nLine3\nLine4\n" > test.txt

The wc command counts the lines, words, and characters in a file. Run the following command to count lines in a given file:

wc -l < test.txt

Leave a Comment

Cancel reply

Your email address will not be published.