0

I'm in a Linux class and one of my assignment questions is to find out the total number of processes running on the server.

I have used the ps -aux command to list all the processes but I was wondering if there was a way to number the output so I can count them easier

3
  • 3
    Be conscious of the XY Problem...
    – Attie
    Commented Oct 9, 2018 at 16:00
  • thanks for the help, I used the ps -aux | wc -l command and that worked
    – cole
    Commented Oct 9, 2018 at 16:05
  • As the answers say, piping to wc-l will give you the number of lines, but it's a good idea to suppress the header line with ps -auxh. Also, ps -auxh | less -N will allow you scroll the output with the lines enumerated.
    – AFH
    Commented Oct 9, 2018 at 16:06

3 Answers 3

2
ps -aux | wc -l

Then subtract the number of lines used in the header and the footer of the command.

wc counts words but the -l counts lines

1
  • Have a look in the man page... --no-headers is handy
    – Attie
    Commented Oct 9, 2018 at 16:03
2

Others have mentioned wc -l for producing a total line count... however there is also nl which might be more in keeping with your "number the output" question - it prepends line numbers:

$ ps -aux --no-headers | nl | head
     1  root         1  0.0  0.0  39872  7532 ?        Ss   Sep24   7:07 /sbin/init
     2  root         2  0.0  0.0      0     0 ?        S    Sep24   0:02 [kthreadd]
     3  root         3  0.0  0.0      0     0 ?        S    Sep24   0:44 [ksoftirqd/0]
     4  root         5  0.0  0.0      0     0 ?        S<   Sep24   0:00 [kworker/0:0H]
     5  root         7  0.0  0.0      0     0 ?        S    Sep24  16:50 [rcu_sched]
     6  root         8  0.0  0.0      0     0 ?        S    Sep24   0:00 [rcu_bh]
     7  root         9  0.0  0.0      0     0 ?        S    Sep24   0:05 [migration/0]
     8  root        10  0.0  0.0      0     0 ?        S    Sep24   0:04 [watchdog/0]
     9  root        11  0.0  0.0      0     0 ?        S    Sep24   0:05 [watchdog/1]
    10  root        12  0.0  0.0      0     0 ?        S    Sep24   0:05 [migration/1]
[...]
1
  • | tail -n=1 | cut -d' ' -f1 if added to the above will show you the number of the last line
    – K7AAY
    Commented Oct 9, 2018 at 22:47
1

Try piping the output to the word count program, wc

ps -aux | wc -l

will give you the total number of lines outputted by the ps command.

Hope this helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .