- Linux Administration Cookbook
- Adam K. Dean
- 166字
- 2021-07-02 14:24:40
How it works...
In this section, we're using the systemctl command to query systemd.
We'll get gradually more granular with our requests, until we've eventually built a query that shows us only what we want to see, that being services that are running right-this-second.
There's an argument to be made for using pipes and grep to accomplish what you want and, depending on your preference, you may find one of these two commands neater than the other, though they accomplish roughly the same thing:
$ systemctl --no-pager | grep service | grep running | column -t
In the previous, we're first printing the default "all" list from systemctl, then we're passing it through grep a couple of times to filter what we want, and finally we're displaying it in a mostly-readable fashion with a column.
$ systemctl list-units --type service --state running --no-legend
Here, we're using one command to get a slightly prettier output than the previous, and we're only using one command to do it.