3 ms·
I'm sure there's a lot more once you get to more advanced stuff, but going through their System examples has me puzzled: > ls | where type == dir or in Bash:
by ghusto 4y ago
I'm sure there's a lot more once you get to more advanced stuff, but going through their System examples has me puzzled:
> ls | where type == dir
or in Bash:
`ls -d`
> ps | where cpu > 0 | sort-by cpu | reverse
or in Bash:
`htop` ?
> ps | where name == Notepad2.exe
> # find process, then ...
> ps | where name == Notepad2.exe | get pid.0 | kill -9 $in
or in Bash:
`pkill Notepad2.exe`
> Pipeline content to clipboard
Or on MacOS:
`anything | pbcopy`
The first example is actually the only one that makes sense to me:
> ls | where type == file
Amazingly, there's no straightforward way to tell `ls` to output only files (that I know of):
`ls -p | grep -v /`
I don't mean to knock it, but I think it's better to learn the standard tools available everywhere than invest any time in tools that aim to lessen the learning curve.
- boustrophedon 4y ago`find . -type f -maxdepth 1`
- AdamJacobMuller 4y ago> Amazingly, there's no straightforward way to tell `ls` to output only files (that I know of): `ls -l|grep -e^-` Unless you meant without pipes/grep in which case I think no, but, you're bumping up against the fact that `ls` is really more of a user-presentation tool than for scripting. Use `find . -type f` maybe with some `-maxdepth 1`
- jiggawatts 4y agoHe’s giving simple examples everyone can quickly understand. When I show people the same advantage that PowerShell has over bash I pick harder problems where bash/gnu tools have no trivial answers. But then people get sour grapes and say “I don’t need to do that kind of thing anyway.” The reality of course is they avoid those harder problems and solve them manually or with different tools (Python). Sorting is as good example, because while commands like ‘ps’ have some built in sorting capability, it is limited and inconsistent with other tools. You can sort by some columns, but not others. Sorting by the same field is often a different option across different tools even if they manipulate the same objects, etc… If you would like a harder problem: kill every process on the machine run by the user “ash” that has used more than 1 hour of total CPU time but only those of his processes that are in the top 5 in the entire system by memory usage. Hint: Don’t kill anyone else’s processes by accident even if their user name is “flash” or if their process name is “bash”. Also don’t confuse instantaneous %CPU with total CPU usage. Did I say total CPU? Oops, I meant total kernel time used! My mistake. Update your a script, that should be a simple change… right?
- dr_kiszonka 4y agoAs with almost everything, Bash is easy once you learn how to use it ; ) I think this tool is useful for people who need to use the terminal right now, without having to spend quite a bit of time learning, e.g., Bash. Your point about the portability of Bash is, of course, valid. It just that sometimes you need to get stuff done quickly without parsing, at times unfriendly, documentation of more mature tools.
- dvdkon 4y agoI think you've partly proven that nushell is useful. `ls -d` doesn't list directories, it lists only the files given as arguments instead of their children. Also, htop is nothing like a scriptable and composable pipeline from ps, and there's no reason `pkill` couldn't co-exist with the equivalent of `kill $(ps | grep Notepad2 | grep -v grep)`. Dozens of specific commands and flags for specific usecases aren't always enough, and, dare I say it, counter to the UNIX philosophy.
- deleted 4y ago[deleted]
- juped 4y agoLiterally nothing you mentioned is a shell builtin, your choice of shell matters not at all.