If I call command systemctl without grep, then formatting looks correctly:

enter image description here

Now I want to filter only lines with 'yarn', but this time line is broken into two parts:

enter image description here

same happens when console is two times wider. How can i fix this?

1 Answer 1


When systemctl’s output isn’t sent to a terminal, e.g. if it’s piped to grep, then it allows each column of its output to grow as much as necessary to fit the longest item in the list. This is what’s happening here: some unit in the list of units has a very long name, and aligning the output of all units produces the large space between yarn.service and loaded failed failed.

To filter the unit output, use systemctl’s built-in pattern matching:

sudo systemctl list-units '*yarn*'

You can limit the output to the lines you’d get with grep with the --no-legend option, avoid colouring and special characters with the --plain option, and avoid starting a pager with the --no-pager option:

sudo systemctl list-units --plain --no-legend --no-pager '*yarn*'

You can specify multiple patterns, the results will include any match to any of the patterns:

sudo systemctl list-units --plain --no-legend --no-pager '*yarn*' '*hdfs*'

There are better sub-commands if you want to retrieve the status of specific units; see for example The "proper" way to test if a service is running in a script.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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