systemd-run — Run a transient systemd unit
Linux / Service and process management / systemd-run.html
Runs a command as a transient systemd service or timer with journal logging and resource control.
Basic Information
| Command Name | systemd-run |
|---|---|
| One-line Introduction | Runs a command as a transient systemd service or timer with journal logging and resource control. |
| Provided by | systemd |
| Official Documentation | https://www.freedesktop.org/software/systemd/man/systemd-run.html |
| Supported Operating Systems | Linux (systemd-based distributions) |
| Installation Status | Installed by default with systemd |
| Category | Linux service and process management (tags: Process and resource management (tags: systemd, service, timer, resource control)) |
What is this command?
systemd-run executes a command under systemd without writing a unit file.
Output goes to the journal and systemd features such as CPU or memory limits and timers apply directly.
What problems does it solve?
- Keep one-off job output in the journal.
- Run with CPU or memory limits.
- Schedule a single future run.
- Run detached from the login session.
Key features
Transient service
Starts the command as a background service and returns immediately.
- When to use: When the job must outlive the session
- What you get: A transient unit managed by systemd
- Limitations: The unit name is needed to check status
Resource limits
Set properties to cap CPU or memory use.
- When to use: When a job must not monopolize the host
- What you get: Execution under the given limits
- Limitations: Requires kernel cgroup support
Timer scheduling
Use --on-calendar and related options to schedule the run.
- When to use: One-off or recurring schedules
- What you get: A scheduled timer unit
- Limitations: Timer state must be checked separately
Installation and usage
Check whether it is installed
systemd-run --version
systemctl --version # systemd must be PID 1
Real-world examples
Transient service
Run as a background service.
# Run a command as a transient service
systemd-run --unit=myjob /usr/local/bin/task.sh
With limits
Limit CPU and memory.
# Cap memory and CPU share
systemd-run -p MemoryMax=512M -p CPUQuota=50% /usr/local/bin/task.sh
Scheduled run
Run once tomorrow at 03:00.
# Schedule a single run
systemd-run --on-calendar='*-*-* 03:00:00' /usr/local/bin/task.sh