When searching for string (no regex etc.) in large file less filename and less -b 1 filename quits or prints it cannot allocate memory. top shows less using roughly about 5% of memory before it dies (1 sec interval).

What other tool can I use that supports large files? The file has only 100 mb of logs.

$ less -V
less 458 (GNU regular expressions)
Copyright (C) 1984-2012 Mark Nudelman

OS details:

$ ulimit -a
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-m: resident set size (kbytes)      unlimited
-u: processes                       15988
-n: file descriptors                1024
-l: locked-in-memory size (kbytes)  64
-v: address space (kbytes)          2048000
-x: file locks                      unlimited
-i: pending signals                 15988
-q: bytes in POSIX msg queues       819200
-e: max nice                        0
-r: max rt priority                 0
-N 15:                              unlimited
$ cat /etc/*rele*
  • 1
    What is your machine and OS ?
    – Kiwy
    Commented Feb 6, 2014 at 22:40
  • What does ulimit -a say?
    – jordanm
    Commented Feb 6, 2014 at 22:40

2 Answers 2


This probably has nothing to do with your memory and everything to do with the way less is written and how much space it allocates for its internal variables.

Anyway, less is really not designed for this, you should use a tool like grep instead:

grep yourQuery file

If you want to see the lines around your query (5 for example), run this:

grep -C 5 yourQuery file

If you have too many matches for that, you can pass the output to less and now you should be able to search through it:

grep -C 5 yourQuery file | less

Of course, if you want to do this manually, you can open the file in a text editor. Any serious editor like vim or emacs will be able to open and search through a 100MB file.

  • vim actually needs Control-c to show contents, not intuitive, but it can handle it. I was not aware of grep -C option - thanks.
    – Rumca
    Commented Feb 6, 2014 at 23:01
  • 1
    @Rumca nothing about vim is intuitive (excellent, yes but not intuitive), just use your favorite editor.
    – terdon
    Commented Feb 6, 2014 at 23:05
  • Yes, I've opened huge files in vi/emacs. Not a pleasant experience... and the editor is even more likely to run out of memory than less (if yout think about it, the data structures to keep track of changes and allow changing the file are bound to be more complex and bulky than those required just to keep track of current position).
    – vonbrand
    Commented Feb 7, 2014 at 1:16
  • Apologies for a side question, does less load the entire file in memory? I also want to note that I use vim for this, and I really love vim as my go-to editor for almost everything (yes, I took a long time to 'grok' it). But it is what it is, not intuitive!
    – 0xc0de
    Commented Sep 21, 2020 at 10:52
  • 1
    @0xc0de no, less does not. See man less: "Also, less does not have to read the entire input file before starting, so with large input files it starts up faster than text editors like vi ".
    – terdon
    Commented Sep 21, 2020 at 10:56

You should strive to run less without line numbers as this is the usual case with large files, less -n . I like to use case insensitive search as well, so it's always: less -ni wherever it's possible (busybox's default less does not support those command line options, for example).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .