↑ ↓ select, Enter open, Esc close

Replace text in a file with sed and keep a backup

Caution: This command changes the system. Understand what it does before you run it.

Adjust the values, the command updates live
user@server
sed -i.bak 's|memory_limit = 128M|memory_limit = 256M|g' php.ini

Replaces every occurrence of ALT with NEU in the file itself, while the original stays next to it as php.ini.bak. The | serves as delimiter so that paths with slashes work without escaping. Run it without -i.bak first to safely check the result on the console.

Note: The search text is a regular expression, characters such as ., *, [ or $ have special meaning and must be escaped with a backslash. If the text itself contains a |, choose a different delimiter such as #.

Also searched as

  • sed find and replace in file
  • search and replace command line linux
  • change config value with sed

Related one-liners

All in Text processing

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.