Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For me,

  > ls -rec . | ? name -match <substring_in_filename>
becomes muscle memory as a pwsh daily driver-type-person (=> PowerShell 7).


For simple matches against one pattern, you may prefer...

    > ls -rec . -filter *substring*`
... as filtering can be offloaded to the "provider" when Get-ChildItem (ls) knows about it.

Even if the filesystem provider doesn't handle patterns any differently from Where-Object (?), you can save the cost of hydrating FileInfo objects only to query and discard most of them.

For multiple patterns or anything that you'd need a regular expression for, Where-Object is superior!


Thanks, I'm not usually doing performance required stuff but when I write a function I always want to know the best way to feed the pipeline, I appreciate it. #snoverville


aka

  find . -iname \*<substring_in_filename>*
(=> V5 Unix from 1971, although the case insensitive -iname was never standardized)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: