Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Powershell equivalent of the command "find | grep 'mystring'"?

What is the Powershell equivalent of the command

find | grep "mystring"

like image 366
applecrusher Avatar asked Jul 08 '15 21:07

applecrusher


2 Answers

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"

like image 176
dpw Avatar answered Nov 09 '22 13:11

dpw


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.
like image 31
hysh_00 Avatar answered Nov 09 '22 13:11

hysh_00