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: & in less hides every line that does not match in the terminal pager

Terminal
~/tips/tip-terminal-less-ampersand-filter

less /var/log/nginx/error.log

Filters a log inside less without quitting and running grep.

You open a log in less, start reading, and wish you had piped it through grep first. You can filter without leaving the pager.

Inside less, type &, then a pattern, then Enter:

less /var/log/nginx/error.log
&timeout

Now only lines that match timeout are shown. The prompt starts with an ampersand as a reminder that lines are hidden. The pattern is a regular expression, so &error|warn keeps both kinds.

Filters stack. Type & with a second pattern and you see only lines that match both, which is handy to narrow a big log step by step. To show everything again, type & and press Enter with nothing after it.

One variation I like: &! followed by a pattern shows the lines that do not match, great for hiding noisy health checks.

&!GET /health

Very old versions of less don’t have the command, and some minimal containers ship BusyBox less, which lacks it too. If & just beeps, check less --version. Searching with / still works everywhere.

Further reading: less(1) Linux manual page

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link