I was doing a very simple search:
grep -R Milledgeville ~/Documents
And after some time this error appeared:
grep: memory exhausted
How can I avoid this?
I have 10GB of RAM on my system and few applications running, so I am really surprised a simple grep runs out of memory. ~/Documents
is about 100GB and contains all kinds of files.
grep -RI
might not have this problem, but I want to search in binary files too.
grep
can discard the buffers it has processed so far. You cangrep
the output ofyes
indefinitely without using more than a few kilobytes of memory. The problem is the size of the lines. – Stéphane Chazelas Sep 10 '13 at 12:51grep
has to hold the full current line in memory. – Stéphane Chazelas Sep 10 '13 at 12:56find
solution, however ^^) – Olivier Dulac Sep 10 '13 at 15:31--null-data
option may also be useful here. It forces the use of NUL instead of newline as an input line terminator. – iruvar Sep 16 '13 at 15:27dd if=/dev/sda | fold -b $((4096*1024*1024)) | grep -a "some string"
to limit the amount of memory required to 4GB – poinu Mar 02 '18 at 16:35