sed -i: edit files in place from the command line

Apply search-and-replace across one or many files on Linux with sed -i, keeping backups with -i.bak.

LinuxsedreplaceeditMedium risk
Run sed -i 's/old/new/g' FILE to rewrite the file directly; use sed -i.bak 's/old/new/g' FILE to keep a backup copy first.

01Command

Command
$ sed -i 's/old-domain.com/new-domain.com/g' *.conf

02What it does

The s/// substitution is well known, but the -i flag is what makes sed an editing tool rather than a filter: it rewrites the file on disk instead of printing to stdout. GNU sed lets you attach a suffix (-i.bak) so the original is preserved, which is the closest thing to undo for a non-interactive edit. Expressions also support address ranges (sed -i '10,20s/x/y/') and can be pointed at many files at once for bulk config changes.

03Risk

RiskMedium risk
!Warning: sed -i without a backup suffix is irreversible — a bad expression silently corrupts every file it touches; also GNU and BSD sed have incompatible -i syntax.

04Undo

Undo
$ git checkout -- *.conf  (or restore from the .bak created by sed -i.bak)

05Sources

  • Sed — ArchWiki
    Arch Linux · community · 2026-09-17
    Evidence: Examples of GNU sed -i in-place editing and -i.bak backup extension usage
  • sed(1P) — POSIX manual page
    man7.org · technical · 2026-09-17
    Evidence: Documents the s/re/replacement/flags substitution, /g global flag, and address ranges

Last verified: 2026-09-17 · Category: Files & Folders