I'm trying to perform a recursive find and replace on a Linux webserver (searches 100,000+ files, but it takes so long that my SSH session times out. Is there a way to only search files named "index.php"? This would cut down on execution time dramatically.
Here is the command I'm using:
$ find . -type f -print0 | xargs -0 sed -i “s%Apples%Oranges%g”
Modify your
find
command to add the-name
option:(I put the
-name
predicate first, on the principle that it's marginally faster than anything which needs tostat()
files, but it may well be thatfind
optimizes for that anyway.)Also, consider a parallel invocation of
xargs
; e.g. with GNUxargs
: