What this template solves
This template is useful when a directory prefix changes and you need to rewrite repeated file paths in configs, scripts, or environment files.
Sample input
/srv/legacy/app
/srv/legacy/cache
keep=/srv/legacy/tmpPrompt to start from
Replace /srv/legacy with /srv/current in the file
Expected command
sed 's#/srv/legacy#/srv/current#g'Tags
Best for
- Update deployment paths after moving a service directory.
- Rewrite repeated mount paths in container or CI config.
- Replace old filesystem prefixes in shell scripts and docs.
How to use this template
- 1Confirm the old path prefix and the new target prefix.
- 2Copy the replacement command with escaped path separators.
- 3Validate on sample input, then run the file-edit variant on the real file.
Template FAQ
How do I replace an old directory prefix across many paths with sed?
A path-friendly delimiter such as `sed 's#/srv/legacy#/srv/current#g'` is a common pattern because it avoids excessive escaping. This makes bulk path rewrites easier to read and safer to reuse.
What files usually need a replace-path-prefix workflow?
This workflow is common in deployment scripts, CI config, container setup, environment files, and migration docs where the same filesystem prefix appears on many lines.
Related templates
Explore nearby sed workflows that target similar replace, cleanup, filtering, or rewrite tasks.
Replace domain names
ReplaceReplace an old domain with a new one in bulk.
sed 's/old\.example\.com/new.example.com/g'Replace ports in bulk
ReplaceReplace every 8080 in a config with 80.
sed 's/8080/80/g'Replace URL paths
ReplaceReplace an old URL path segment with a new one across many lines.
sed 's#/v1/api#/v2/api#g'