Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I do service --status-all I get something like this:

[ ? ]  webmin
[ ? ]  whoopsie
[ + ]  winbind
[ - ]  x11-common

I want to show just the running ones ([ + ]) so I did

service --status-all | grep +

which highlights them, but how do I make it exclude the other lines?

Also, is this showing actual running services or just ones which are scheduled to run at startup?

share|improve this question
add comment

1 Answer

You can change the amount of surrounding lines grep outputs (called the "context") with options -C [num] or --context=[num].

Usually, the default option for grep is to print no context, so the command you used should be fine. You can force it to show only matching lines by service --status-all | grep + -C 0.

To exclude matching lines, use -v or --invert-match. So, you can pipe the original command through | grep -v '[ ?' | grep -v '[ -' to get rid of lines with - or ? as their status. You can also combine multiple match strings by using escaped "or" (the pipe symbol), like grep -v '[ ?\|[ -'.

However, as service for some reason directs its output to stderr instead of the normal stdout, the output streams need to be combined with |& for the grep to work properly. So, the working command here would be service --status-all |& grep +.

share|improve this answer
    
service --status-all | grep + -C 0 does exactly the same thing. Using grep -v also doesn't work. However, this works: ` service --status-all > services.txt cat services.txt | grep +` –  eggbert Aug 14 '13 at 15:17
    
Ok, service behaves erratically, please see the last paragraph of the edited answer. –  Jawa Aug 14 '13 at 19:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.