What is the Windows equivalent of the Linux/Unix command wc -l?

Basically, how do you count the number of lines output from a command on the Windows command line?


The Linux/Unix "line count" command, wc -l, has a Windows equivalent of find /c /v "".

How does this work?

According to Raymond Chen of the The Old New Thing, this functions as such since

It is a special quirk of the find command that the null string is treated as never matching.

The inverted (/v) count (/c) thus effectively counts all the lines; hence, the line count.

Example usage

To count the number of modified files in a subversion working copy:

svn status -q | find /c /v ""

Such a command can be used to mark a build as "dirty" if the count is not 0, i.e., there are uncommitted changes in the working copy.

To obtain a line count of all your Java files:

(for /r %f in (*.java) do @type "%f") | find /c /v ""

The command find /c /v "" can also be added to a batch file if required.  Remember to duplicate the % characters in batch files.


A working PowerShell equivalent is Measure-Object -line with some additional formatting required, e.g., (directory listing for simplicity),

(ls | Measure-Object -line).Lines
| improve this answer | |

In PowerShell, to obtain a line count of all your java files:

type *.java | Measure-Object -line
| improve this answer | |
  • 3
    welcome to superuser: - the question was about CMD not powershell, if you can answer the OP please edit your answer. these may help How to Answer, How to Ask, help center again welcome to superuer and i hope you return, thankyou – mic84 Aug 6 '18 at 9:52
  • 12
    Thanks @mic84. The question is about Windows command line. And Microsoft is trying to replace CMD with PowerShell: networkworld.com/article/3143196/windows/… So this is a quite useful answer. – user3808394 Aug 7 '18 at 10:41

findstr /n /r .

This is a limited regex, so /n shows the line number of the match, and "." is match any char.

| improve this answer | |
  • 2
    The question isn’t how to display the file with line numbers; the question is how to determine the number of lines in the file. – Scott Jul 16 '19 at 0:29
  • Look at the number of the last line, and that's how many lines are in the file. The "find" command works, too, but maybe findstr will be useful in some cases. I have found it to be. – Gary Gatten Jul 19 '19 at 19:16
  • That’s not a very user-friendly answer, especially given that we’ve received a couple of other answers that are more direct.  But, if that’s your answer, then please edit your answer to make it clearer and more complete. – Scott Jul 19 '19 at 19:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.