4

I recently discovered that you can start and immediately background long-running source code searches piped to less:

grep -r something | less &

is there a way to direct less to read more of the output into memory than it's currently displaying "in the background" so that when I decide to look at the results of my search I don't need to wait.

4

By default, if you pipe commands, the bash shell uses the pipe(3) libc call to weave the file descriptors of the child tasks. Its default internal buffer size is only 64K.

However, there is a tool

buffer

for the task, included into most distros. By default, it uses 1MB buffer, but you can increase it to any big. For example

grep ..anything, anywhere.. | buffer -m $[1<<30] | less &

will be likely enough. :-) It has many other nice features (for example, it can work like a dd, or it can print hashes to the stderr after n-byte chunks), it is a... killer app. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.