Today’s Linux One-Liner

Try this:

ps -eo user,pcpu,pid,cmd | sort -r -k2 | head -6

What the heck does that do?

It gives me this output:

greg 6.7 5901 /usr/lib/firefox-3.0/firefox
root 1.5 5441 /usr/bin/X :0 -br -audit 0 -auth /var/lib/gdm/:0.Xauth -nolisten tcp vt7
greg 0.5 7216 /usr/bin/liferea-bin
greg 0.1 7401 gnome-terminal
greg 0.1 5790 gnome-panel --sm-client-id default1

(results will vary)

This is a list of the top five most processor hungry applications running on my system right now.

ps stands for “processor stuff” and it returns stuff about the processor.

The e option tells ps to look at every process running on the system.

The o option allows the user to specify which of the many columns of data ps can produce.

The output of the ps command is piped, using the pipe symbol “|” to the sort command.

Sort takes a file or a stream of data (same thing, really) and … sorts it!

The r option sorts it in reverse. The k option tells sort which column to sort on (columns are defined by, say, the spaces between words and stuff) …. so here we are sorting on the second column.

The output of sort is then piped to the head command. The head command takes the top ten lines (the head) of a file and sends it back out again (‘head’ is a filter). But if you give it a number, it put out that number of lines.

Since ps puts out a row of column headers, to get the most processor intensive processes we ask head to give us 6 lines.

(Oh, it’s actually “processor snapshot”)


  1. #1 Sojournposse
    August 12, 2009

    Very intriguing. We should have a linguist and a mathematician explaining, say, the concept behind a simple string of javascript (what is that command: is it algebra, or linguistics?). I would like to know why php reads the way it is. I can tolerate some of the languages, but php. If it weren’t for WordPress…

    Many dismiss this aspect of computer science as ‘geek’, without realising that even a simple concept like predictive texting on mobile phone is actually combined effort in linguistics, design and mathematics.

    We don’t have many blogs like that here, I notice. Wonder why.