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]
[...]
wc-l
will give you the number of lines, but it's a good idea to suppress the header line withps -auxh
. Also,ps -auxh | less -N
will allow you scroll the output with the lines enumerated.