5 ms·
I am not sure what your example does. How does it differ from find . -name ".docx" ls -Recurse | ? { $_.Name -match ".+docx" } And, if these are the same, wh
by ratboy666 10y ago
I am not sure what your example does. How does it differ from
find . -name ".docx"
ls -Recurse | ? { $_.Name -match ".+docx" }
And, if these are the same, why type in twice as many characters as a command? Actually,
ls -R | grep "\.docx$"
is, I think, closer in spirit.
Now, the issue is things further in the pipeline, I imagine.
The find solution allows selection on type name, type, date, depth, mounts, properties, file system type, ownership, relative age, inode, symbolic link. find actions include delete, exec, print, quit. This can pass on needed information to further pipeline commands.
However, an interactive shell is meant to allow expression of commands with a reasonable minimum of keyboarding (thus ls and not dir). I could argue that the "Unix" command should be
find . -n ".docx"
(because the most common -n... option used is -name).
I think, to be fully reasonable the find command you want
is
find . -regex ".*\.docx$"
which is still shorter than the PS example. I am not sure
that for most interactive tasks, PS is a win. It does appear
to be more elegant, but only usage over time will show if
it is indeed more productive. I am looking for academic productive studies to be done, now that both bash and PS are available on common platforms.
- Analemma_ 10y agoIf you're just talking about ls/dir, then PowerShell isn't really a win. The advantages are clearer when you start talking about lots and lots of commands. A lot (but not all!) Unix tools have flags to control their output format or input filters, but that means you have to memorize different flags for all of them. OTOH, in PS you just pipe to where/sort/select and they work for everything. IMO PowerShell has better separation of concerns.
- yumaikas 10y agoI should have made it clear that this wasn't an example of Powershell being superior to bash, just what I can remember from that little script.
- jnky 10y agoIn Powershell you can also do this: ls -Recurse -Include *.docx or even this: ls -Recurse *.docx which is really quite similar your find command.