I sometimes have to look through files that are several gigs and have noticed that finding what I am looking for with grep is much faster than with less. Why could that be? I am talking about looking for a certain tag/word, not even any complicated regex.

  • Not an answer, but have you considered using grep and then a pipe to pass the results onto less? – ridogi Jan 12 '10 at 7:19
  • 1
    Yes, I usually use grep with -A/B/C to get some context around what I am searching for but sometimes I need more flexibility as I am looking at log files and need to be able to scroll around and incrementally search from there on/before – naumcho Jan 12 '10 at 21:18

By default, 'less' calculates line numbers, which can slow it down. Try using the '-n' option to suppress line number calculations and see if that speeds things up.

  • 2
    I think the line counting happens once grep has found your match - then you see "Calculating line numbers" and it takes a while before it lets you do anything, but you can cancel that with ctrl+c. It doesn't look like the -n helps with the actual search speed. – naumcho Jan 12 '10 at 21:25
  • That did the trick for me. Noticed a huge difference (as in tens of seconds vs instantaneous response) when opening a nearly 10GB log file and hitting shift G to get to the end of the file. – Marcello Romani Sep 4 '15 at 9:51
  • @MarcelloRomani shift-G has nothing to do with search though – Martin Konecny Apr 21 '17 at 19:06

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.