What is the Powershell equivalent of the command
find | grep "mystring"
The equivalent of find
in PowerShell is Get-ChildItem
and the equivalent of grep
is Select-String
, so you have:
Get-ChildItem -Name | Select-String "mystring"
You can use the common aliases of those commands ( gci
and sls
, respectively) to shorten it a bit:
gci -n | sls "mystring"
If you don't have to do follow the folders and just search within a certain folder, you do not need the find and Get-ChildItem. You can specify PATH to Select-String like this. (same as >grep "mystring" ./*)
PS> Select-String "mystring" .\*
Select-String [-Pattern] <String[]> [-Path] <String[]>
-Path <String[]>
Specifies the path to the files to be searched. Wildcards are permitted. The default location is the local directory.
Specify files in the directory, such as "log1.txt", "*.doc", or "*.*". If you specify only a directory, the command fails.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With