Skip to main content

less Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for navigating, searching, and controlling output with the less pager in Linux

The `less` command is a pager for viewing text one screen at a time. This cheatsheet covers navigation keys, search patterns, startup options, and practical workflows for logs and command output.

Basic Usage

Common ways to open files and piped output in less.

CommandDescription
less file.txtOpen a file in the pager
less /var/log/syslogRead a system log file
command | lessPipe command output into less
less +G file.txtOpen a file and jump to the end
less +/pattern file.txtOpen a file and jump to first match

Move through content quickly in the pager.

KeyDescription
SpaceMove forward one page
bMove backward one page
EnterMove forward one line
k / yMove backward one line
d / uMove forward / backward half a page
gJump to top of file
GJump to bottom of file
50gJump to line 50
FFollow mode — stream new content as it is appended (press Ctrl+C to stop)
qQuit less

Search and Match Navigation

Find text and move between matches.

KeyDescription
/patternSearch forward for pattern
?patternSearch backward for pattern
nNext match in current search direction
NPrevious match in current search direction
&patternShow only lines matching pattern
& (empty)Clear &pattern filtered view

Useful Options

Flags that improve readability in daily use.

CommandDescription
less -N file.txtShow line numbers
less -S file.txtDisable line wrap (horizontal scrolling)
less -R file.txtShow ANSI colors in output
less -i file.txtCase-insensitive search by default
less -F file.txtQuit automatically if content fits one screen
less -X file.txtKeep screen content after quitting

Log and Output Workflows

Practical examples for troubleshooting and analysis.

CommandDescription
less +F /var/log/syslogFollow a log file live (like tail -f); press Ctrl+C to stop and search
journalctl -xe | lessPage through recent systemd logs
dmesg | lessInspect kernel messages page by page
ps aux | lessBrowse long process listings
git log | lessRead long commit history safely
grep -R \"ERROR\" /var/log | lessReview search results interactively

Troubleshooting

Quick fixes for common less issues.

IssueCheck
Search does not find expected textRetry with exact case or use -i for case-insensitive search
Color codes look brokenUse less -R when input includes ANSI colors
Lines wrap and are hard to readUse less -S and move sideways with arrow keys
Pager exits immediatelyContent may fit one screen; remove -F if you need manual paging
You opened from pipe and lost contextRerun command with | less and search using /pattern

Use these guides for deeper command and text-processing workflows.

GuideDescription
less Command in LinuxFull less tutorial with examples
head Command in LinuxShow the first lines of files
tail Command in LinuxFollow file growth and recent lines
grep Command in LinuxSearch text patterns in files
wc Command in LinuxCount lines, words, and bytes