Linux sed and awk Cheat Sheet/Edit in place with backup

Create a backup copy while editing.

Section: sed Substitution

Edit in place with backup

bash
bash
sed -i.bak 's/debug/info/g' app.conf
Explanation

Creates `app.conf.bak` before replacing the original file.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing sed Substitution
Edit a file in place
Modify the original file directly.
OpenIn sheetbashsame section
Replace first occurrence per line
Substitute one match in each line.
OpenIn sheetbashsame section
Replace all occurrences per line
Substitute every match on each line.
OpenIn sheetbashsame section
Use an alternate delimiter
Make path replacements easier to read.
OpenIn sheetbashsame section
Delete blank lines
Remove empty lines from output.
OpenIn sheetbash1 tag match
Delete comment lines
Skip lines that begin with `#`.
OpenIn sheetbash1 tag match