🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

less Command

Beginner Text Processing man(1)

View file contents with scrolling and search

👁 13 views 📅 Updated: Mar 15, 2026
SYNTAX
less [OPTION]... [FILE]

What Does less Do?

less is an interactive file viewer that displays text one screen at a time. Unlike cat which dumps entire files, less allows scrolling, searching, and navigating through files of any size efficiently.

less loads files lazily — it does not need to read the entire file before displaying, making it fast even for gigabyte-sized log files. It supports forward and backward searching, pattern highlighting, following growing files (like tail -F), and multiple file viewing.

less is the default pager for man pages and many other system commands. Its name is a play on the older more command, with the philosophy that "less is more" — it provides all the features of more plus backward scrolling and much more.

Options & Flags

OptionDescriptionExample
-N Show line numbers less -N script.py
-S Chop (truncate) long lines instead of wrapping less -S wide-data.csv
-i Case-insensitive search less -i /var/log/syslog
-F Quit if file fits in one screen less -F short.txt
-R Display ANSI color codes (raw control characters) git diff | less -R
+F Follow mode (like tail -f, press Ctrl+C to stop) less +F /var/log/syslog
-X Do not clear screen on exit less -X file.txt

Practical Examples

#1 View a file

Opens the file for interactive viewing. Use q to quit.
$ less /var/log/syslog

#2 View with line numbers

Displays the file with line numbers on the left side.
$ less -N /etc/nginx/nginx.conf

#3 Search within file

Open file, then type /failed to search forward. Use n for next match, N for previous.
$ less /var/log/auth.log\n/failed

#4 Follow a growing log

Follows the file like tail -f. Press Ctrl+C to stop following and browse normally.
$ less +F /var/log/syslog

#5 View colored output

Preserves ANSI color codes in piped output for readable display.
$ git log --oneline --graph --color | less -R

#6 View wide CSV without wrapping

Shows CSV with line numbers, truncating long lines. Use arrow keys to scroll horizontally.
$ less -SN data.csv

Tips & Best Practices

Essential navigation keys: Space/f = page down, b = page up, g = start, G = end, /pattern = search forward, ?pattern = search backward, n = next match, q = quit.
Mark positions: Press m followed by a letter to mark a position. Press ' followed by the same letter to return to it. Great for navigating large files.
Highlight all matches: After searching with /pattern, all matches stay highlighted as you scroll. Use ESC-u to toggle highlighting off.

Frequently Asked Questions

How do I search in less?
Type / followed by your search term and press Enter. Use n to jump to the next match and N for the previous match. For case-insensitive search, start less with -i.
How do I go to a specific line number?
Type the line number followed by g. For example: 100g goes to line 100. Or use :100 to go to line 100.
What is the difference between less and more?
less supports backward scrolling, searching, and does not load the entire file into memory. more only scrolls forward. less is more feature-rich in every way.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →