Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to only get the number of lines of a file

Tags:

linux

bash

How do I get the number of lines of a file in linux?

I only want the number of lines, not the filename.
I want to do it in a single command, without grep or another utility.

wc -l sample.txt   

Output

5 sample.txt

Desired Output

5
like image 906
Shivam Agrawal Avatar asked Aug 16 '13 05:08

Shivam Agrawal


1 Answers

Try this

wc -l < sample.txt

wc doesn't print out the filename if it reads the file through standard input. The < feeds the file via standard input.

like image 175
Prashant Kumar Avatar answered Oct 02 '22 15:10

Prashant Kumar