brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: less -i ignores case in searches unless your pattern has a capital letter

Less
~/tips/tip-less-i-ignore-case-search

less -i /var/log/syslog

Makes searches in less case-insensitive, except when you type a capital letter.

Searching a log in less with /error misses Error and ERROR, and that is exactly the line you wanted. There’s a flag for it.

less -i /var/log/syslog

With -i (long form --ignore-case), searches ignore case, as long as the search pattern contains no uppercase letter. So /error finds all three spellings, while /Error matches only that exact one. That is the same smart-case behavior many editors have.

Its uppercase sibling does the other thing:

less -I /var/log/syslog

The -I flag (--IGNORE-CASE) ignores case in all searches, even when you type capitals.

You don’t need to start less with the flag. Typing -i inside a running less toggles the option. It then shows a short message saying which mode is on. To make it permanent, put it in the LESS environment variable, for example in your shell profile:

export LESS="-i"

A caveat: if you already use LESS for other options, add -i to the same string instead of overwriting it. Every less that runs under your shell reads the variable, including the one that man starts.

Two other commands from less --help fit this use. &pattern displays only the matching lines, which turns a long log into a short list. ESC-u toggles the search highlighting if it gets in the way.

Further reading: less manual, less home page and docs

More Less tips less +F /var/log/syslog All Less tips (2) All topics

Link