Using ps
format options
ps
allows you to specify a custom output format.
ps ax o pcpu
The above command would return a single column of CPU usage data.
Why cut
doesn't work
cut
's default delmiter is the tab character. ps
uses spaces in its output, so you would have to use cut -d' ' -f3
to select the third field (as cut
sees it).
The problem with using cut is that it views anything adjacent to a delimiter as a field. Since ps
prints multiple adjacent spaces between fields,
$ ps aux
...
para␣␣␣␣␣␣␣462␣␣0.0␣␣0.0␣␣13492␣␣1792␣tty1␣␣␣␣␣Ss+␣␣05:52␣␣␣0:00
root␣␣␣␣␣␣␣484␣␣1.8␣␣0.5␣137020␣45112␣?␣␣␣␣␣␣␣␣Ss␣␣␣05:52␣␣␣0:20
para␣␣␣␣␣␣␣490␣␣0.0␣␣0.0␣␣28072␣␣1708␣tty1␣␣␣␣␣S␣␣␣␣05:52␣␣␣0:00
...
$ ps aux | cut -d' ' -f3
...
␣
␣
␣
...
cut
will print a column of spaces if you ask it for the third field. To make matters worse, the number of spaces that ps
outputs between each field is not always uniform among the rows, so you can't just use cut -d' ' -f12
You would end up with results like this:
...
4.6
0.0
0.0
␣
␣
0.0
0.1
␣
␣
␣
...