What is the Windows equivalent of the Linux/Unix command
Basically, how do you count the number of lines output from a command on the Windows command line?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
The Linux/Unix "line count" command,
wc -l, has a Windows equivalent
find /c /v "".
It is a special quirk of the
findcommand that the null string is treated as never matching.
The inverted (
/v) count (
/c) thus effectively counts all the lines;
hence, the line count.
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 ""
find /c /v "" can also be added to a batch file if required.
Remember to duplicate the
% characters (
%%f) in batch files.
A working PowerShell equivalent is
Measure-Object -line — some additional formatting is required though, e.g. a directory listing for simplicity:
(ls | Measure-Object -line).Lines