Assorted less(1) tips
Blog post by Tim Chase (2025-11-11), aggregated from a Reddit discussion.
Tips
- Opening multiple files:
less README.txt file.c *.md - Adding files after launch:
:e file.h - Navigating between files:
:n(next),:p(prev),:x(rewind to first) - Removing files:
:ddeletes current file from argument list - Line-number navigation:
countG(e.g.,3141Gjumps to line 3141) - Percentage navigation:
count%(e.g.,75%goes to 3/4 through file) - Search modifiers:
!(invert match),*(cross-file),@(from first file),@*(both) - Filtering:
&patternshows matching lines;&!patternhides matching lines - Bookmarks:
m+ letter to set,'+ letter to jump back. All 52 letters available. Applies across files. - Bracket matching: Type
(,[, or{on first screen line to jump to matching close - Custom match pairs:
alt+ctrl+foralt+ctrl+bfollowed by a pair - Toggling options:
-+ option letter (e.g.,-Sfor line wrap,-Nfor line numbers) - External commands:
!commandruns shell command - Default options:
LESS="-RNe"in .bashrc - Tags: ctags support (author has never used it)
- Editing:
vopens file in $VISUAL - Logging:
oorOwrites stdin to file
HN Discussion Highlights
less +Ffor follow mode, Ctrl-C to break, F to resume (teeray)-Xflag to prevent screen clearing (JayGuerette)&filtering for log debugging; regex supported but slow (etra0)-Lto skip nroff preprocessing on rotated logs (inejge)~/.lesskeyfor custom keybindings; macOS lacks this, needs Homebrew less (jez)^qto quit without clearing screen,qclears it (ilyagr)- Pipe command with marks for saving text selections to file (Rediscover)
!bashfrom less as root = privilege escalation vector (GuB-42)- OpenBSD's man provides tags to less for section jumping (somat)
-Fauto-quits if file fits on one screen; alternative pagers likemost(fragmede)ssaves piped data to file (btdmaster)- lesspipe enables syntax highlighting and file rendering (alkh)
- Vim muscle memory transfers to less; keybindings feel intuitive (eulgro)
- PCRE support useful for code analysis; bookmarks as "microtools" (jsrcout)
- Regex engine unreasonably slow on large files (jemfinch)
- "If you want security, unset LESSOPEN" (anthk)
LESSSECURE=1disables dangerous features like!(jmholla)