问题描述:

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.
相关阅读:
Top