Today I needed to count file lines, but I happened to not have a Linux environment on hand.
Counting Code Lines on Linux
On Linux this is a very simple thing:
find . -name "*.py" | wc -l
This line can easily count the lines of all py-suffixed files in the current directory.
Counting Code Lines on Windows
This time we shouldn’t use cmd but PowerShell instead.
Powershell is an automation configuration framework developed by Windows based on .NET.
(Basically it’s the new command line.)
Then we can type:
dir .\ -Recurse *.py | Get-Content | Measure-Object
We can see the output:
Count : 1253
This means py-suffixed files in the current directory have a total of 1253 lines.