count number of lines in terminal output

后端 未结 4 1098
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-29 19:46

couldn\'t find this on SO. I ran the following command in the terminal:

>> grep -Rl \"curl\" ./

and this displays the list of files wher

4条回答
  •  死守一世寂寞
    2021-01-29 20:32

    Putting the comment of EaterOfCode here as an answer.

    grep itself also has the -c flag which just returns the count

    So the command and output could look like this.

    $ grep -Rl "curl" ./ -c
    24
    

    EDIT:

    Although this answer might be shorter and thus might seem better than the accepted answer (that is using wc). I do not agree with this anymore. I feel like remembering that you can count lines by piping to wc -l is much more useful as you can use it with other programs than grep as well.

提交回复
热议问题