Skip to main content
Replace a pattern across matching files. Preview with dry_run before writing. See Find files for the same name and content rules.

Parameters

Response

Files with zero occurrences are not listed and are not rewritten, so their mtime is untouched.

Replace safely

  • Literal by default. Without regex, $1 in the replacement stays $1.
  • Capture groups need regex. With regex: true, $1, $2, and ${name} expand to the matching groups.
  • Each file is replaced as a whole. A reader sees the old file or the new file.
  • Metadata is preserved. Mode, owner, and group stay on the rewritten file.
  • Binary and oversized files are skipped, using the same rules as Find files: a NUL byte in the first 8 KiB, invalid UTF-8, or a file above 8 MiB.
  • Directory symlinks are not followed, so a link cannot rewrite files outside path.
  • Dry run first for wide patterns. dry_run returns the per-file counts without writing.

Endpoint

POST /v1/agents/runtime/{runtime_id}/files/replace