The command:

service --status-all

Takes too long to iterate through all of the services especially when all I want from the output is the name (I don't care if it's running or not). Is there a faster way to retrieve the name of a service that contains a known character pattern?

With Ubuntu 14.04 and Ubuntu 16.04 using different service names for php-fpm (php5-fpm in Ubuntu 14.04 and php7.0-fpm in Ubuntu 16.04), developers supporting multiple platforms need to be able to determine the service name.

If I run the below command on a slower computer:

service --status-all 2>&1 | grep -F -- "-fpm" | awk '{print $4}'

It takes several seconds (up to 5 seconds) to return "php7.0-fpm".

Developers that have to interact with these services need a faster way to determine the name of the service since they continually change from one OS version to another.

Anyone know of a better and faster way to do this?

In the meantime, I filed this bug here:


I don't know how else I can accomplish what I need to do quickly...


If you already know that this depends on the version of Ubuntu, why not just check the version instead?

case $(lsb_release -sc) in

Alternately, you could test for the service files in /etc/init.d (since all current FPM packages provide an /etc/init.d script):

find /etc/init.d/ -type f -iname '*-fpm' -printf "%P\n"
  • The whole point is that I don't want to have to hard code it against the ubuntu version, but that somewhat helps. Thanks! – OwN Jan 10 '18 at 10:46

Looks like I'll go with the following approach:

    fpmService=$(ls /etc/init.d 2>&1 | grep -F -- "fpm");
    if [ -z "$fpmService" ]; then
        fpmService=$(ls /lib/systemd/system 2>&1 | grep -F -- "fpm" | grep -o "[^(service)]*" | sed "s/\.$//"
    if [ -z "$fpmService" ]; then
        fpmService=$(ls /lib/systemd/system 2>&1 | grep -F -- "' . $service . '" | grep -o "[^(service)]*" | sed "s/\.$//")

Stupid, but it works... the service command should still provide us with an interface to do this...

  • The second and third ls | grep pipes are unnecessarily complex - find /lib/systemd/system -name '*-fpm*' -exec basename {} .service \; will get you the result more easily. – muru Jan 10 '18 at 10:57

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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