• How to find / replace a string in multiple files in linux

How to search and replace a string in multiple files in linux

find ./ -type f -exec sed -i 's/old_string/new_string/g' {} \;

For global case insensitive:

find ./ -type f -exec sed -i 's/old_string/new_string/gI' {} \;

Ignoring .git directory:

find . -not -path '*/\.git/*' -name '*.rb'  -exec sed -i 's/old_string/new_string/g' '{}' \;

This article was last modified: March 27, 2025, 11:51 a.m.

0 Comments

Please log in to leave a comment.

Add or change tags.

A comma-separated list of tags.

Share

Hacker News

Top