← 返回命令列表

Linux command

systemd-escape 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Escape the given text

systemd-escape [text]

Reverse the escaping process

systemd-escape -u [escaped_text]

Treat the given text as a path (collapses slashes and "..")

systemd-escape -p [/path/to/resource]

Append a unit suffix to the escaped text

systemd-escape --suffix [service] [text]

Insert the escaped text into a template unit

systemd-escape --template [getty@.service] [tty1]

Build a .mount unit name from a path

systemd-escape -p --suffix=mount [/tmp/waldi/foobar/]

Mangle partially-unescaped input into a valid unit name

systemd-escape -m [some string]

说明

systemd-escape converts arbitrary strings into valid systemd unit name components, or reverses that conversion. Systemd unit names have strict naming rules: only alphanumerics, `:`, `_`, and `.` are permitted; other characters are encoded as `\xNN` sequences, and `/` becomes `-`. The tool is especially useful when constructing .mount or .swap units from paths, or when instantiating template units such as `foo@.service` with a dynamic instance string.

参数

-u, --unescape
Reverse the escaping (decode). Cannot be combined with --suffix= or --mangle.
-p, --path
Treat the argument as a file system path, simplifying slashes and ".." components. Useful for generating strings that match the `%f` specifier.
--suffix=_suffix_
Append a unit type suffix such as `service` or `mount` to the escaped string. Incompatible with --template=, --unescape, and --mangle.
--template=_template_
Insert the escaped string at the `@` position of a template unit name like `foobar@.service`. With --unescape, extracts and unescapes just the instance portion.
-m, --mangle
Escape only obviously-unescaped characters and append a suitable unit suffix if missing. Incompatible with --suffix=, --template=, and --unescape.
--instance
Used with --unescape --template=: print only the instance portion of a template unit name.
-h, --help
Show help text.
--version
Show version information.

FAQ

What is the systemd-escape command used for?

systemd-escape converts arbitrary strings into valid systemd unit name components, or reverses that conversion. Systemd unit names have strict naming rules: only alphanumerics, `:`, `_`, and `.` are permitted; other characters are encoded as `\xNN` sequences, and `/` becomes `-`. The tool is especially useful when constructing .mount or .swap units from paths, or when instantiating template units such as `foo@.service` with a dynamic instance string.

How do I run a basic systemd-escape example?

Run `systemd-escape [text]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -u, --unescape do in systemd-escape?

Reverse the escaping (decode). Cannot be combined with --suffix= or --mangle.