Powerful Editing Commands for Linux
Editing one file is easy. Editing a hundred files with the same precision is where Linux shines. Bash, grep, regex, sed, and Vim are a stack that turns repetitive cleanup into a repeatable, reviewable workflow.
Step 1: Find the exact target with grep
Use grep to locate the lines and confirm the scope before you touch anything.
# Find every file that contains the old string
grep -RIn "OldCompany" .
# Count how many hits
grep -R "OldCompany" . | wc -l
# List filenames only (great for previews)
grep -RIl "OldCompany" .
If the pattern is complex, use regex. Example: match IPs, version numbers, or templated variables.
# Regex: find version numbers like v1.2.3
grep -RInE "v[0-9]+\.[0-9]+\.[0-9]+" .
Step 2: Prototype the change with sed (no writes)
Dry run first. Use sed without -i to preview how the edit looks.
# Preview changes in a single file
sed -E 's/OldCompany/NewCompany/g' README.md | less
# Preview on multiple files
grep -RIl "OldCompany" . | xargs -n 1 sed -E 's/OldCompany/NewCompany/g' | less
Step 3: Apply the change at scale
Once the preview looks correct, use sed -i to edit in place.
# Edit files in place (GNU sed)
grep -RIl "OldCompany" . | xargs -n 1 sed -i -E 's/OldCompany/NewCompany/g'
# If you want backups:
grep -RIl "OldCompany" . | xargs -n 1 sed -i.bak -E 's/OldCompany/NewCompany/g'
Need to change only lines that match a condition? Use address ranges.
# Only replace inside an nginx block
sed -i -E '/server_name/,/}/ s/example.com/example.org/g' nginx.conf
Regex basics that pay off fast
Regular expressions let you match patterns instead of exact strings.
^start of line,$end of line.any character,\swhitespace+one or more,*zero or more(...)capture groups,\1backreference
# Swap "last, first" to "first last"
sed -E 's/^([^,]+),\s*(.+)$/\2 \1/' names.txt
Vim: surgical edits across many files
Vim is perfect when you want high confidence changes with confirmation and review.
# Open many files (from a glob)
:args **/*.conf
# Find a pattern and populate the quickfix list
:vimgrep /server_name/ **/*.conf
:copen
# Do a confirmed replacement across all args
:argdo %s/example.com/example.org/gc | update
Macros are also deadly for repeating transformations. Record once, replay on every match.
# Record a macro "q" and replay it 20 times
qq...q
20@q
Bash glue: repeatable pipelines
Bash is the conductor that connects every tool. Use it to build safe, repeatable pipelines.
# Replace a token only in .env templates
for f in $(grep -RIl "APP_URL" .); do
sed -i -E 's/^APP_URL=.*/APP_URL=https:\/\/rebelwithlinux.com/' "$f"
done
w3m: edit with live documentation nearby
w3m is a terminal web browser that keeps reference docs and examples one keystroke away while you edit. Use it to grab exact syntax or to pull down text you want to transform.
# Read a man page style doc in the terminal
w3m https://man7.org/linux/man-pages/man1/sed.1.html
# Dump a page to plain text for quick parsing
w3m -dump https://example.com/faq | less
Pair it with split panes in your terminal: editor on the left, w3m on the right. Keep the command you want, verify, then execute.
tmux: split panes, persist sessions
tmux keeps long editing sessions stable and organized. Split panes for editor, docs, and logs, and detach to keep work running on a remote server.
# Start a new session
tmux new -s edit
# Split panes (horizontal, vertical)
Ctrl-b "
Ctrl-b %
# Split with command shortcut
tmux split -h
# Move between panes
Ctrl-b o
# Detach and later reattach
Ctrl-b d
tmux attach -t edit
Use one pane for your editor, one for grep/sed previews, and one for verification. The session survives disconnects, so you can safely edit over SSH.
OpenCode: fast, safe batch edits
OpenCode can draft multi-file edits from a short prompt, but it shines when you give it guardrails. Tell it the exact files, patterns, and a verification command so the change stays predictable.
# Example prompt you can reuse
"Update all nginx server_name entries to example.org in *.conf, \
preview with grep, then apply with sed -i, and show verification commands."
# After the edit, verify
grep -RIn "example.org" .
Verify after the change
Always verify that the old string is gone and the new one is present.
# Make sure no old strings remain
grep -RIn "OldCompany" .
# Confirm the new string
grep -RIn "NewCompany" .
Automate the boring, verify the critical, and never edit by hand what the terminal can do in seconds.
These tools are small, sharp, and composable. Together, they give you the power to refactor at scale without fear.