ps aux | grep [a]pache2 | nl

count and number lines of output, useful for counting number of matches

Write each FILE to standard output, with line numbers added. With no FILE, or when FILE is -, read standard input.
Sample Output
     1	root      2459  0.0  0.4  24068  7408 ?        Ss   Dec09   0:00 /usr/sbin/apache2 -k start
     2	www-data  5191  0.0  0.5  26312 10068 ?        S    Dec11   4:28 /usr/sbin/apache2 -k start
     3	www-data  5909  0.0  0.5  26312 10064 ?        S    Dec11   4:02 /usr/sbin/apache2 -k start
     4	www-data  5991  0.0  0.5  26312 10252 ?        S    Dec11   4:05 /usr/sbin/apache2 -k start
...
    98	www-data 12931  0.0  0.4  25144  8308 ?        S    13:28   0:00 /usr/sbin/apache2 -k start
    99	www-data 12932  0.0  0.4  25144  8312 ?        S    13:28   0:00 /usr/sbin/apache2 -k start
   100	www-data 12933  0.0  0.4  25144  8316 ?        S    13:28   0:00 /usr/sbin/apache2 -k start

4
By: donnoman
2009-12-17 18:48:09

1 Alternatives + Submit Alt

What Others Think

grep -c
CrazyDiamond · 439 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: