linux command find and replace

Author: Thorpe Lee(, Front&Back-end Developer, posted on 2015-11-25 16:55:36

Print - 프린트하기


It is a useful command on Linux, I sometimes need to find someting and than replace them to other string. but I forget that command. that's whay now I am posting it how to use the command


Find and Replace

If you want to find "Orange" and then replace to "Apple",Look at the example bleow. there are 2 ways below


First way

find ./ -type d \( -name log -o -name log \) -prune -o -type f -exec grep -w Orange -n -H {} \; -exec sed -i s/Orange/Apple/g {} \; 

Second way

find ./* -name *.* -exec sed -i s/Orange/Apple/g {} \;