How to run sed on over 10 million files in a directory?

Posted by Sandro on Super User See other posts from Super User or by Sandro
Published on 2011-03-14T02:03:12Z Indexed on 2011/03/14 8:12 UTC
Read the original article Hit count: 472

Filed under:
|
|

I have a directory that has 10144911 files in it. So far I've tried the following:

  • for f in ls; do sed -i -e 's/blah/blee/g' $f; done

Crashed my shell, the ls is in a tilda but i can't figure out how to make one.

  • ls | xargs -0 sed -i -e 's/blah/blee/g'

Too many args for sed

  • find . -name "*.txt" -exec sed -i -e 's/blah/blee/g' {} \;

Couldn't fork any more no more memory

Any other ideas on how to create this kind command? The files don't need to communicate with each other. ls | wc -l seems to work (very slow) so it must be possible.

© Super User or respective owner

Related posts about bash

Related posts about find