Linux find and replace all strings in a directory [transfer]

 

Find files in a folder containing a string

Example: Find all files containing "rubyer.me" in the /usr/local directory.

?
1
grep -lr 'rubyer.me' /usr/local/ *

vim replace all string method in single file

Example: replace all old in the current file with new

?
1
2
:%s /old/new/g
#%表示替换所有行,g表示替换一行中所有匹配点。

Replace files containing strings in a folder

sed combined with grep
example: To change the old in all files under the directory /www to new, do this:

?
1
sed -i "s/old/new/g" ` grep old -rl /www `

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326776731&siteId=291194637
Recommended