To list all failed units/services on a Linux system using systemd, you can use the systemctl
command with the --failed
option. The following command will list all units/services that have failed to start or have been in a failed state:
systemctl --failed
This command will display a list of all units that have failed to start or have been in a failed state, including the unit name, the loaded state, and the active state.
You can also use the list-units
option along with --failed
option to get a more detailed information about the failed units:
systemctl list-units --failed
The above command will give you the information like the unit’s name, description, load state, active state, and substate.
You can also filter the failed services by using --type=service
option with the above commands.
systemctl --failed --type=service
or
systemctl list-units --failed --type=service
This will list only the failed services, instead of all failed units.
Once you’ve identified the failed unit/service, you can use the systemctl
command to start, stop, or restart it, or you can use the journalctl
command to view the logs for the unit/service and diagnose the issue.