For example:
cat /etc/passwd
What is the easiest way to count and display the number of lines the command outputs?
For example:
cat /etc/passwd
What is the easiest way to count and display the number of lines the command outputs?
wc
is the unix utility which counts characters, words, lines etc. Try man wc
to learn more about it. The -l
option makes it print only the number of lines (and not characters and other stuff).
So, wc -l <filename>
will print the number of lines in the file <filename>
.
You asked about how to count number of lines output from a command line program in general. To do that, you can use pipes in unix. So, you can pipe the output of any command to wc -l
. In your example, cat /etc/password
is the command line program you want to count. For that you should do:
cat /etc/password | wc -l