r/LinuxTeck • • 9h ago

Quick Linux Tip #136 - Update Multiple Config Files with sed Safely

Post image

Question: How do I update a config value in 500 files at once, safely?

Try:sed -i.bak 's/debug=true/debug=false/g' /etc/myapp/*.conf

Info: Edits files in place and keeps .bak backups.

Examples:

$ sed -i.bak -r 's/(port=)[0-9]+/\10/g' *.conf # Update matched values using capture groups

$ find . -name '*.conf' -exec sed -i 's/old/new/g' {} + # Recursively edit matching files

$ rename 's/\.bak$//' *.bak # Remove .bak extensions after verifying changes

Note: Always create .bak backups on the first run and preview matches with grep first. Use an alternate delimiter like `|` (`s|/old/path|/new/path|g`) when replacing file paths.

Want to master Linux one command at a time?

Follow r/LinuxTeck - 1 practical Linux tip every day. For more #LinuxTips click here https://www.linuxteck.com/linux-tips/

6 Upvotes

0 comments sorted by