Forrest logo
back to the systemd-run tool

systemd-run:tldr:44feb

systemd-run: Start a transient service that does not get cleaned up after it terminates with a custom environment variable.
$ sudo systemd-run --remain-after-exit --set-env=${name}=${value} ${command} ${argument1 argument2 ---}
try on your machine

This command is used to run a command as a systemd transient unit. Here's a breakdown of the different components:

  • sudo: It is used to execute the subsequent command with administrative/root privileges.

  • systemd-run: It runs the command as a transient unit within the systemd system. Transient units are units that are dynamically created and removed as needed.

  • --remain-after-exit: This flag specifies that the transient unit should not be automatically removed after the command exits. It allows the unit to persist even after the command execution is complete.

  • --set-env=${name}=${value}: This flag is used to set an environment variable within the transient unit. Here, ${name} represents the name of the environment variable, and ${value} represents its value. This allows you to pass specific environment configurations to the command being executed.

  • ${command}: This is the main command that you want to execute within the transient unit. It can be any executable or script.

  • ${argument1 argument2 ---}: These represent the arguments that you want to pass to the command. They are specified after the command name, separated by spaces. The --- is used as a separator to differentiate between the command and its arguments, ensuring all subsequent arguments are treated as arguments and not options.

Overall, this command executes a given command within a systemd transient unit, allowing you to customize environment variables and specify arguments for the command. The sudo prefix ensures the command is executed with administrative privileges.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the systemd-run tool