0

I'm wondering how can I escape the following command from PowerShell so that it works?

PS C:\Users\buster\Documents\> find -name \*.c 

PowerShell says: error not found *.c

PS C:\Users\buster\Documents\> find -name *.c 

PowerShell says: error not found *.c

Walter
  • 39
  • 2

2 Answers2

1

If you used find like that (without the full path) you most likely used the find.exe that ships with Windows (C:\Windows\system32\find.exe), which is more akin to grep than to Unix find. You get that behavior because Windows searches all directories in $env:PATH for files with the given name (and one of the extensions listed in $env:PATHEXT if no extension was specified), and executes the first match. Since %windir%\system32 is usually at the beginning of the PATH, executables from there take precedence.

You could add C:\msys64\msys64\usr\bin to the beginning of the PATH (before %windir%\system32), although I wouldn't recommend that. A better way would be to define an alias for the command:

New-Alias -Name 'find' -Value 'C:\msys64\msys64\usr\bin\find.exe'

Aliases take precedence over files. You could put the alias definition in your PowerShell profile so that it's automatically loaded whenever you start PowerShell.

Or you could simply use ls -r -fi '*.c' (short for Get-ChildItem -Recurse -Filter '*.c'), which would be the PowerShell way.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
0

Ok false alarm..

Apparently its a case of windows having an executable with the same name as msys2's find.exe under c:\windows\system32 and the windows command getting higher priority in the path list. After explicitly typing out the full path to the msys64 version of find.exe it works.

PS C:\Users\buster\Documents\> C:\msys64\msys64\usr\bin\find -name \*.c

Also, Turns out there's a better way to find *.c files native to cmd.exe that you can call from powershell like this:

PS C:\Users\buster\Documents\> cmd /c dir /S /B *.v
Walter
  • 39
  • 2