351

It seems like the only way to do this is to pass the -i parameter in when you initially run less. Does anyone know of some secret hack to make something like this work

/something to search for/i
fedorqui
  • 275,237
  • 103
  • 548
  • 598
mk.
  • 26,076
  • 13
  • 38
  • 41

5 Answers5

509

You can also type command -I while less is running. It toggles case sensitivity for searches.

gilad905
  • 2,842
  • 2
  • 16
  • 23
Juha Syrjälä
  • 33,425
  • 31
  • 131
  • 183
120

You can also set the environment variable LESS

I use LESS=-Ri, so that I can pump colorized output from grep into it, and maintain the ANSI colour sequences.

Another little used feature of less that I found is starting it with +F as an argument (or hitting SHIFT+F while in less). This causes it to follow the file you've opened, in the same way that tail -f <file> will. Very handy if you're watching log files from an application, and are likely to want to page back up (if it's generating 100's of lines of logging every second, for instance).

sanmiguel
  • 4,580
  • 1
  • 30
  • 27
  • 4
    Following with less is SO much more useful than with tail. Especially logs with a lot of action. – Svish May 21 '14 at 10:31
  • 8
    @Svish You could say `less` is more :) – Martin Konecny Jul 09 '15 at 05:39
  • 9
    @MartinKonecny `less` may be more, but `less` is not [`more`](https://en.wikipedia.org/wiki/More_(command)) let alone [`most`](https://en.wikipedia.org/wiki/Most_(Unix)) – sanmiguel Aug 04 '15 at 18:46
  • @sanmiguel I didn't know most, tried it and sidescroll is really cool, thanks – ᐅdevrimbaris Jan 29 '16 at 19:08
  • I would use `less +F --follow-name some.file`. `+F` alone not working for me. – WesternGun May 07 '18 at 15:18
  • 4
    `less` is more than `more`, `most` is more than `less` | `less` is more, but more `more` than `more` is, so `more` is less `less`, so use more `less` if you want less `more`. – Sumit Jain Oct 05 '18 at 05:05
  • While this works when you start `less` yourself, for things like `hg log` or `git` stuff that use less, this unfortunately doesn't work for me. Luckily remembering `-I` once less is running isn't too bad. – scohe001 Mar 07 '19 at 23:13
36

Add-on to what @Juha said: Actually -i turns on Case-insensitive with SmartCasing, i.e if your search contains an uppercase letter, then the search will be case-sensitive, otherwise, it will be case-insensitive. Think of it as :set smartcase in Vim.

E.g.: with -i, a search for 'log' in 'Log,..' will match, whereas 'Log' in 'log,..' will not match.

Utku
  • 2,025
  • 22
  • 42
Antony Thomas
  • 3,576
  • 2
  • 34
  • 40
  • 19
    Actually, if *any* letter, not just the first one, is uppercase the search will be case sensitivite. An important difference (and indicentally how I prefer it to be). This is also how vim's smartcase works. – Johannes Hoff Nov 13 '12 at 00:53
  • In Vim you can also say `/\clog` to switch to case-insensitive search. – Darko Veberic Aug 08 '19 at 12:41
14

It appears that you can summon this feature on a per search basis like so:

less prompt> /search string/-i

This option is in less's interactive help which you access via h:

less prompt> h
...
  -i  ........  --ignore-case
                  Ignore case in searches that do not contain uppercase.
  -I  ........  --IGNORE-CASE
                  Ignore case in all searches.
...

I've not extensively checked but the help in less version 487 on MacOS as well as other Linux distros lists this option as being available.

On MacOS you can also install a newer version of less via brew:

$ brew install less
$ less --version
less 530 (POSIX regular expressions)
Copyright (C) 1984-2017  Mark Nudelman

References

slm
  • 15,396
  • 12
  • 109
  • 124
  • @IlikeSerena - it may be an issue w/ specific versions of `less`. – slm Nov 26 '14 at 14:07
  • 1
    @slm which `less` did you try this on ? Doen't work on my `less 458 (GNU regular expressions)` (aptitude says `less 458-2` FWIW) – hdl Aug 31 '15 at 13:23
  • @hdl - I do not have access to the system currently but was on whatever version of `less` that's included w/ Fedora 19/20. – slm Aug 31 '15 at 14:14
  • @slm Thanks, probably a more recent release than 458-2, such as 458-6 as this particular one was built for Fedora on 2014-02-10 according to http://koji.fedoraproject.org/koji/packageinfo?packageID=759 and since you posted this on Feb 22 '14... – hdl Aug 31 '15 at 14:56
  • 1
    Doesn't work on mac with less 487 (POSIX regular expressions) – Sumit Jain Oct 05 '18 at 05:01
  • @SumitJain - you could try installing newer version of less on MacOS, see updates. NOTE: that the `-i` switch is listed in version 487's help. – slm Oct 05 '18 at 12:13
  • This doesn't work with `less 590 (GNU regular expressions)` in Ubuntu – PerseP Aug 11 '23 at 09:59
12

When using -i flag, be sure to enter the search string completely in lower case, because if any letter is upper case, then its an exact match.

See also: the -I (capital i) flag of less(1) to change this behavior.

joe
  • 329
  • 3
  • 4