sodcalculator

10 Tech How-To

systemctl list dependencies RHEL Guide

Guide 10-47163 · Updated · Step by step

This guide shows you how to use systemctl list-dependencies on Red Hat Enterprise Linux to see the full dependency tree of a systemd unit (like a service or target). You’ll learn how to read the output, filter it, and troubleshoot common issues. No prior systemd knowledge is required, but basic comfort with the command line is assumed.

What You’ll Need

  • Access to a RHEL system (version 7 or later, though 8/9 are most common).
  • A user account with sudo privileges (some commands require root).
  • A terminal emulator (GNOME Terminal, Konsole, or SSH session).

Step-by-Step

  1. Open a terminal. If you’re on the graphical desktop, press Ctrl+Alt+T or find Terminal in the applications menu. If you’re SSH’d in, you’re already there.
  2. Check the status of a unit (optional but helpful). Run systemctl status sshd to confirm the unit name and that it’s loaded. Replace sshd with any unit you care about (e.g., firewalld, crond, multi-user.target).
  3. List dependencies for a unit. Run the basic command: systemctl list-dependencies sshd. This shows a tree of all units that sshd depends on (its “requires” and “wants” dependencies). The output uses indentation and box-drawing characters to show the hierarchy.
  4. Include reverse dependencies. To see what depends on sshd (i.e., units that pull it in), add the --reverse flag: systemctl list-dependencies --reverse sshd.
  5. Expand all dependencies. By default, the tree only shows the immediate dependencies of each unit. To see the full recursive tree, use --all: systemctl list-dependencies --all sshd. This can be very long, so pipe it to less to scroll: systemctl list-dependencies --all sshd | less.
  6. Filter by dependency type. Use --type= to show only specific types (e.g., requires, wants, after). For example: systemctl list-dependencies --type=wants sshd shows only “wants” dependencies. You can combine multiple types with commas: --type=requires,wants.
  7. Filter out target units. Targets are like runlevels (e.g., multi-user.target). To hide them and focus on actual service/device/mount units, use --no-pager with grep: systemctl list-dependencies --no-pager sshd | grep -v '.target'. Or use the --plain flag to remove the tree characters for easier parsing: systemctl list-dependencies --plain sshd.
  8. Check a target (e.g., default boot target). To see what services start at boot, use: systemctl list-dependencies default.target. This is a great way to audit which services are enabled.
  9. Use with grep to find a specific unit. To quickly check if a particular unit is in the dependency tree, run: systemctl list-dependencies --all sshd | grep 'network'. This will show any line containing “network”.
  10. Save output to a file. Redirect the output for later analysis: systemctl list-dependencies --all sshd > deps.txt. Then open with less deps.txt.

Common Mistakes

  • Forgetting the unit suffix. Unit names often have a suffix like .service, .target, .socket. If you type sshd without the suffix, systemd usually finds it, but for custom units you must include the full name (e.g., myapp.service).
  • Misreading the tree. The output shows a tree, but not every line is a direct dependency. A line with a box-drawing character (like ├─ or └─) is a child of the previous unit. A line with just spaces is a continuation of the previous branch. Use --plain to avoid confusion.
  • Assuming all dependencies are started. list-dependencies shows the dependency graph, not the current state. A unit may be listed but not active. Check with systemctl status for actual state.
  • Using --type incorrectly. The --type= flag expects dependency types like requires, wants, after, before, conflicts. It does not accept unit types like service or target. To filter by unit type, use grep instead.
  • Not using --all when needed. By default, the command only shows one level of dependencies for each unit. If you want the full recursive tree, you must add --all, otherwise you’ll miss many dependencies.

Tips

  • Combine with systemctl list-units. To see which dependencies are actually loaded and active, run systemctl list-units --type=service --state=running and compare with the dependency list.
  • Use --no-pager for scripting. When piping to grep or a file, add --no-pager to avoid the pager interfering.
  • Understand the difference between requires and wants. requires means the unit will fail if the dependency fails; wants means the dependency is started if possible, but the unit will not fail if it’s not available. This is crucial for troubleshooting.
  • Check the After= and Before= dependencies. These are ordering dependencies, not hard requirements. They control the order of startup, not whether a unit starts. You can see them with systemctl show -p After -p Before sshd.
  • Use systemd-analyze for timing. If you’re investigating slow boot, systemd-analyze blame and systemd-analyze critical-chain are more useful than list-dependencies.

Troubleshooting

  • Command not found. If you get bash: systemctl: command not found, you’re likely not on a systemd-based system. RHEL 7+ uses systemd, but if you’re on an older version (RHEL 6 or earlier), you’ll use chkconfig and service instead. Upgrade or use the appropriate commands.
  • Unit not found. If you see Unit sshd.service not found., the unit name is wrong or the unit is not installed. Use systemctl list-unit-files | grep ssh to find the exact name.
  • Permission denied. Some units (especially system-level ones) may require root to list dependencies if they’re not world-readable. Use sudo systemctl list-dependencies sshd to run with elevated privileges.
  • Output is too long. The full tree for a complex service like graphical.target can be hundreds of lines. Use --plain and filter with grep, or save to a file and open in an editor.
  • Dependencies show as “not-found”. If you see lines like ● foo.service - not-found, it means the dependency is listed but the unit file is missing. This often happens after a package is removed. Check with systemctl status foo.service and reinstall the package if needed.
  • Tree is not expanding. If you only see one level and not the full tree, you forgot --all. Add it and try again.

Frequently Asked Questions

What is the difference between requires and wants dependencies?

requires is a hard dependency: if the required unit fails to start, the unit that requires it will also fail. wants is a soft dependency: the wanted unit is started if possible, but if it fails, the dependent unit still starts.

How do I see only the dependencies that are actually enabled?

Use systemctl list-dependencies --all --state=active to show only dependencies that are currently active (loaded and running). This filters out disabled or failed units.

Can I list dependencies for a socket or timer unit?

Yes, the command works for any unit type. For example, systemctl list-dependencies sshd.socket or systemctl list-dependencies backup.timer.

Why does list-dependencies show targets like multi-user.target?

Targets are logical groups of units. Services often have a dependency on a target to ensure they start at the right time during boot. It’s normal to see them in the tree.

How can I see the dependency tree in a more readable format?

Use --plain to remove the tree characters and --no-pager to avoid paging. Then you can sort or filter with standard text tools like sort or grep.

Does this command work on RHEL 7, 8, and 9?

Yes, systemctl list-dependencies is available in all RHEL versions that use systemd, which is RHEL 7 and later. The output format is consistent across these versions.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →