PowerShell FINDSTR eqivalent? PowerShell FINDSTR eqivalent? powershell powershell

PowerShell FINDSTR eqivalent?


Here's the quick answer

Get-ChildItem -Recurse -Include *.log | select-string ERROR 

I found it here which has a great indepth answer!


For example, find all instances of "#include" in the c files in this directory and all sub-directories.

gci -r -i *.c | select-string "#include"

gci is an alias for get-childitem


Just to expand on Monroecheeseman's answer. gci is an alias for Get-ChildItem (which is the equivalent to dir or ls), the -r switch does a recursive search and -i means include.

Piping the result of that query to select-string has it read each file and look for lines matching a regular expression (the provided one in this case is ERROR, but it can be any .NET regular expression).

The result will be a collection of match objects, showing the line matching, the file, and and other related information.