![]() By the way, in the last example, you could group by any Get-Process object property and you can use Get-Process | Get-Member to see quickly see what properties are available. If you really wanted to, you can still manipulate text streams with the Select-String cmdlet but there's rarely a need to do so. That's because PowerShell passes objects (with various properties) between cmdlets and not data streams. Notice that there's not a hint of text stream processing in any of these PowerShell examples. Xfce4-power-manager 15 0.4 /usr/bin/xfce4-power-manager Xfce4-terminal 18 16.68 /usr/bin/xfce4-terminal Here's a snippet of that output: HandleCount: 18 ![]() Now say that in addition to the above, you'd like to group by handle count? It couldn't get much easier, just add the -GroupBy HandleCount argument to the Format-Table cmdlet (yes, that's what they're called): Get-Process | Sort-Object -Property HandleCount, CPU | Format-Table -Property Name, HandleCount, CPU, Path -GroupBy HandleCount ![]() Xfce4-power-manager 15 0.39 /usr/bin/xfce4-power-manager Xrdp-chansrv 18 0.05 /usr/sbin/xrdp-chansrv Xfce4-session 18 0.12 /usr/bin/xfce4-session Xfce4-terminal 18 16.39 /usr/bin/xfce4-terminal Pwsh 128 81.1 /opt/microsoft/powershell/7/pwshĬhrome 52 216.36 /opt/google/chrome/chromeĬhrome 44 151.13 /opt/google/chrome/chrome As can be seen, the table is sorted by handle count, then by CPU time (note the descending CPU times for the three processes using 18 handles): Name HandleCount CPU PathĬhrome 165 375.13 /opt/google/chrome/chrome The PowerShell to do this is fairly straightforward: Get-Process | Sort-Object -Property HandleCount, CPU | Format-Table -Property Name, HandleCount, CPU, PathĪnd here's a snippet of the output. View the list as a table showing process name, handle count, CPU time, and full process file path?.Sort the list in descending order by handle count followed by CPU usage time, then. ![]() For example, say you'd like to do the following: Pretty slick really but we're processing text streams, which can quickly become quite complicated. The grep command grabs multiple lines containing "inet6", the head command grabs the first of these, and awk prints the second field (i.e., the second string) in the line, producing the desired IPv6 value. One approach might be: ifconfig | grep inet6 | head -1 | awk '' For example, say you'd like the IPv6 address of your Linux machine. That said, one of the common issues with the Linux CLI is that text stream processing is often required to get the desired result. There is nothing in the traditional Windows CLI (cd, dir, copy, del, etc.) as powerful as awk, sed, head, tail, tsort, uniq, split, etc. When comparing the commands of the traditional Windows command-line interface (CLI) with those of a Linux CLI, there's really no comparison. ![]()
0 Comments
Leave a Reply. |