Linux command
systemd-run 命令
安全
权限或系统影响较大,执行前请核对目标。
常用示例
Start
sudo systemd-run [command] [arguments]
Start
systemd-run --user [command] [arguments]
Start
sudo systemd-run -u [name] --description [string] [command]
Start
sudo systemd-run -r --set-env=[name]=[value] [command]
Start
sudo systemd-run --on-calendar=[calendar_event] [command]
Run
systemd-run -r --pty [command]
Set
systemd-run -p MemoryMax=[bytes] -p CPUQuota=[percentage]% --wait [command]
Use
[command1] | systemd-run -P [command2] | [command3]
说明
systemd-run runs programs in transient scope or service units managed by systemd. This allows applying resource controls, creating timers, and proper service management for ad-hoc commands. The tool is useful for running commands with specific resource limits (CPU, memory), creating one-shot timers, and ensuring proper cleanup and logging through systemd.
参数
- --user
- Run under user service manager
- -u, --unit _name_
- Unit name for the transient service
- --description _text_
- Description for the unit
- -r, --remain-after-exit
- Keep unit after process exits
- --set-env _name=value_
- Set environment variables
- --on-calendar _spec_
- Create a timer unit
- --pty
- Allocate a pseudo-TTY
- -p, --property _name=value_
- Set unit properties
- --wait
- Wait for service completion
- -P, --pipe
- Enable pipe mode for use in pipelines.
- -t, --pty
- Run interactively with a PTY attached (alias variant).
- -q, --quiet
- Suppress informational messages.
- --scope
- Create a transient .scope unit instead of a .service unit.
- --slice _NAME_
- Add the unit into the specified slice.
- --working-directory _DIR_
- Set the working directory for the invoked command.
- --uid _USER_, --gid _GROUP_
- Run the command as the given user/group.
- --nice _N_
- Set scheduling priority for the invoked command.
FAQ
What is the systemd-run command used for?
systemd-run runs programs in transient scope or service units managed by systemd. This allows applying resource controls, creating timers, and proper service management for ad-hoc commands. The tool is useful for running commands with specific resource limits (CPU, memory), creating one-shot timers, and ensuring proper cleanup and logging through systemd.
How do I run a basic systemd-run example?
Run `sudo systemd-run [command] [arguments]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --user do in systemd-run?
Run under user service manager