Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a recursive find and replace from the command line?

Is there a simple way to recursively search all files in a directory hierarchy for a term (e.g. port) and replace all occurrences of that term with another (e.g. port-lookup).

I have tried the suggestions in this post, but they are only applicable for a single file.

like image 909
Jade Yao Avatar asked Nov 18 '25 07:11

Jade Yao


1 Answers

Try this

find ./ -type f -exec sed -i -e 's/port/port-lookup/g' {} \;

If you don't want to change file modification time

grep -rl 'port' /search_in_this_dir | xargs sed -i 's/port/port-offset/g' 
like image 77
Udara S.S Liyanage Avatar answered Nov 20 '25 20:11

Udara S.S Liyanage



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!