Skip to main content

Linux command: less

07 July 2026

Sooner or later a file is too big for the screen. You run cat on a log and thousands of lines fly past, gone before you can read them. This is the exact moment Linux hands you to less: a viewer that stops, holds the text still, and lets you move through it at your own pace, forward and backward, without loading the whole file first.

1. The basics

The job of less is to show you a file (or the output of another command) one screen at a time. It is called a pager, because it turns a long stream of text into pages you can page through. When you view a manual with man, read a git diff, or check the output of systemctl status, you are almost always looking at less without realising it.

Two things make less special. First, like ls, it is safe: it only reads, it never changes the file. You can open a production configuration file or a huge log and you cannot damage anything. Second, it is fast on any size of file. Unlike a text editor, less does not read the whole file before it shows you the first screen. Open a ten-gigabyte log and the first page appears instantly, because less only reads as far as it needs to.

The command that lets you actually read what your system is telling you. It sits, quietly, behind almost every long piece of output on a Linux machine.

This article starts with the simplest possible use and builds up to searching, following live logs, and the tricks that make less feel like a tiny read-only editor. Along the way you will learn why it has such an odd name, and why it quietly became the standard pager on every Linux system.

The right mental model: less does not print your file, it opens it. You are now inside a viewer with its own keyboard commands, and you leave it by pressing q. Nothing happens to the file itself.

Back to top

2. Where the Name Comes From

The name less is a joke. The manual page sums it up in a few words:

"less - opposite of more"

Before less there was an older pager called more. It showed a file one screenful at a time and printed --More-- at the bottom, waiting for you to press space for the next page. But more had a serious limitation: it could only go forward. Once a page had scrolled past, you could not easily go back to it.

When Mark Nudelman built a better pager that could scroll both ways, he named it as a pun on its predecessor. The English saying is "less is more". So the tool that does more than more is called less.

more   =  page forward only
less   =  page forward AND backward (the "opposite of more")

The joke has a serious point behind it: less really is more capable than more, and on modern Linux systems more is often just a link to less running in a limited mode.

Back to top

3. A Short History

The idea of a pager is older than less. The original more command appeared at the University of California, Berkeley, and shipped in early BSD Unix around 1980. It solved a real problem of the teletype and early terminal era: output that scrolled off the top of the screen faster than a human could read it.

Mark Nudelman began writing less in 1984 to fix the biggest weakness of more: the inability to scroll backward. His new pager spread across the Unix world through Usenet, the way software was shared at the time, and it kept gaining features that more never had: regular-expression search, following a growing file, and viewing compressed files directly.

EraMilestone
~1980 more ships in BSD Unix (forward paging only)
1984 Mark Nudelman starts less, adding backward scrolling
mid-1980s less spreads across Unix through Usenet
1990s less becomes the default pager on GNU/Linux
Today The viewer behind man, git, and systemctl

Today less is part of the standard toolkit on essentially every Linux distribution, and it is the default value of the PAGER environment variable that programs like man and git use when they need to show you long output.

A tool named as a joke in 1984 is now the invisible viewer behind most of the text you read on a Linux server. Good design hides in plain sight.

Back to top

4. Simple Use Cases

4.1 The Simplest Possible Use

Give less a filename. It opens the file and shows you the first screen.

$ less /var/log/syslog

The file does not scroll past. It sits still. At the bottom left you usually see a colon (:), which is the prompt telling you that less is waiting for a command. From here you move around with the keyboard, and you leave with q.

4.2 Moving Around

The movement keys come from two older tools: more and the vi editor. You do not need all of them. These few cover almost everything:

KeyWhat it does
Space or f Forward one screen (f for forward)
b Back one screen (b for backward)
Enter or j Down one line
k Up one line
d / u Down / up half a screen (down, up)
g / G Jump to the start / end of the file
Ng / N% Jump to line N / to N percent through the file
= Show the file name and where you are (line, percent)
q Quit

The j and k keys are the same up-and-down keys used in the vi editor, so learning them here pays off elsewhere. The numbered jumps are handy in a big file: type 50g to go straight to line 50, or 25% to land a quarter of the way in. When you lose track of where you are, press = for the file name, current line number, and how far through you are. And if you ever feel lost, press h for a built-in help screen, and q to leave it again.

4.3 Reading Piped Output

The other everyday use of less is at the end of a pipe. When any command produces more output than fits on the screen, send it into less with the pipe character (|):

$ ls -l /etc | less           # a long directory, one screen at a time
$ dmesg | less                # kernel messages
$ ps aux | less               # every running process

Here less is not opening a file on disk; it is reading the text that the command on the left produced. Everything else works the same: page with Space, search, and quit with q.

4.4 Leaving the Screen Clean or Full

By default, when you quit less, the file disappears and your terminal returns to how it looked before. That is usually what you want. If instead you want the text to stay on screen after you quit (handy when you want to keep a few lines visible), use the -X option:

$ less -X notes.txt

The -X flag (short for no-init) stops less from clearing the screen on exit. Its opposite is the default, which keeps your scrollback tidy.

Back to top

5. Moderate Use Cases

5.1 Searching: the Real Reason to Use less

Searching is where less earns its place. Press /, type a word, and press Enter. It jumps to the next line that contains it and highlights every match.

/error                # jump forward to the next line containing "error"

Then move between matches without retyping:

KeyWhat it does
/text Search forward for "text"
?text Search backward for "text"
n Next match (same direction)
N Previous match (opposite direction)

The search text is a regular expression, not just a plain word, so you can search for patterns:

/error|warning        # lines containing "error" OR "warning"
/^root                # lines that START with "root"
/[0-9][0-9][0-9]      # any three digits in a row

There is a close cousin of search that is even more powerful. Press &, type a pattern, and less hides every line that does not match, showing only the ones that do. It is like running grep without leaving the file:

&error               # show ONLY lines containing "error"
&                    # press & then Enter to clear the filter

This turns a noisy log into just the lines you care about, and you can still scroll and search within the filtered view. Clear it by typing & with an empty pattern to bring every line back.

5.2 Ignoring Case While Searching

By default a search for error will not match ERROR. Start less with the -i flag (short for ignore-case) and searches become case-insensitive:

$ less -i application.log

The clever part: with -i, a lowercase search ignores case, but the moment you type an uppercase letter in your pattern, the search becomes case-sensitive again. So /error matches everything, while /Error matches only the capitalised form. This is almost always the behaviour you want.

5.3 Showing Line Numbers

The -N flag (short for line numbers) prints a line number in front of every line. This is invaluable when a program tells you "syntax error on line 214" and you need to find it:

$ less -N config.yaml
      1 server:
      2   host: localhost
      3   port: 8080

You do not have to decide in advance. You can turn line numbers on while less is already open by typing -N and pressing Enter; typing it again turns them off. Most options work this way at runtime.

5.4 Handling Very Long Lines

By default less wraps long lines onto the next screen row. For files with very long lines, such as minified code or wide log entries, this can be hard to read. The -S flag (short for chop long lines) truncates each line at the screen edge instead, so one file line stays on one screen row:

$ less -S wide-data.csv

With -S active, you scroll sideways to see the rest of a line using the left and right arrow keys. This turns less into a simple way to inspect wide CSV or TSV data.

5.5 Jumping to a Place on Startup

You can tell less where to begin. A plus sign followed by a command runs that command as soon as the file opens:

$ less +G huge.log        # open at the END of the file
$ less +/timeout app.log  # open at the first line matching "timeout"
$ less +100 script.sh     # open at line 100

Opening a log straight at the end with +G is a common habit: the newest messages are usually the ones you came to read.

Back to top

6. Advanced Use Cases

6.1 Following a Growing File Live

This is the feature many people switch to tail -f for, without knowing less already does it. Press Shift+F (the F command) and less scrolls to the end and keeps watching, printing new lines as they are written to the file. It behaves like tail -f.

$ less /var/log/nginx/access.log
      # then press  F  to follow new lines as they arrive
      # press  Ctrl-C  to stop following and return to normal browsing

The advantage over tail -f is real: press Ctrl-C and you are back in a full pager, where you can scroll backward through what just streamed by and search it. You can even start in follow mode directly with less +F logfile. This "watch, then stop and search" loop is one of the most useful things less can do.

6.2 Setting Default Options with the LESS Variable

If you always want the same options, you do not have to type them every time. The LESS environment variable holds options that less applies automatically. Put a line like this in your ~/.bashrc:

export LESS="-iRFX"

Read letter by letter, that means: ignore case in searches (-i), show colours correctly (-R), quit automatically if the whole file fits on one screen (-F), and do not clear the screen on exit (-X). Command-line options you type still override the variable, so it only sets your defaults.

6.3 Viewing Colours and Control Characters

Many programs produce coloured output using invisible escape codes. Piped into a plain pager, those codes show up as noise like ESC[31m. The -R flag (short for raw control chars) tells less to render the colours instead of showing the codes:

$ git log --color=always | less -R     # keep git's colours
$ grep --color=always error app.log | less -R

This is why git works so well inside less: git sets its pager to less -R by default, so its coloured diffs and logs look right.

6.4 Opening Several Files at Once

Give less more than one filename and it lets you step between them:

$ less *.log

Once open, move between files with these commands:

CommandWhat it does
:n Next file
:p Previous file
:x Back to the first file

6.5 Marks and Jumping Into an Editor

Inside a long file you can drop a bookmark. Press m followed by any letter to set a mark at the current position, then press a single quote (') followed by the same letter to jump straight back to it later.

ma        # set mark "a" here
'a        # later, return to mark "a"

And if reading turns into editing, press v. This opens the current file in the editor named by your EDITOR or VISUAL environment variable (often nano or vim). When you save and quit the editor, you land back in less. It is a smooth bridge from "just looking" to "making a change".

Back to top

7. Something Most Users Do Not Know

7.1 less Can Read Inside Compressed Files

Here is the detail that surprises people. On most Linux systems, less can open a compressed file and show you the text inside, without you unzipping it first:

$ less access.log.gz          # reads the text, not the compressed bytes
$ less report.pdf             # shows extracted text on many systems
$ less archive.tar.gz         # lists what is inside the archive

This is not magic built into less. It works through an input preprocessor called lesspipe (or lesspipe.sh), which distributions wire up through the LESSOPEN environment variable. When you open a file, less quietly runs it through lesspipe first, which knows how to decompress a .gz file, pull text out of a PDF, or list the contents of an archive. You can see whether it is set up with echo "$LESSOPEN".

7.2 You Have Been Using less All Along

Many commands do not print long output directly to your terminal. They hand it to a pager, and that pager is almost always less. When you run any of these, you are inside less:

  • man ls - the manual page is displayed by less.
  • git log, git diff, git show - git pipes them through less.
  • systemctl status - long service output opens in less.

This is why the same keys (Space, /, q) work in all of them. They are not separate viewers; they are the same less underneath. Which program gets used is controlled by the PAGER environment variable, and git has its own GIT_PAGER.

7.3 Knowing Where less Stops

Part of expertise is knowing when a different tool fits better. less is for reading; when you want to process text, other tools take over:

NeedUseWhy
Print a short file and move on cat No need to open a viewer for a few lines
Watch a log grow forever tail -f Lighter when you only need the live end
Filter lines by pattern grep Extracts matching lines for further use
Edit the file vim / nano less only reads; press v to hand over

The rule of thumb: reach for less when you want to look through text at your own pace, and reach for the tools above when you want to do something with it.

Back to top

8. Best Practices

  • Reach for less, not cat, on anything long. If a file might be more than a screen, open it with less. You keep control instead of watching it scroll away.
  • Learn the core five keys. Space and b to page, / to search, n for the next match, and q to quit. Everything else is a bonus.
  • Open big logs at the end. Use less +G file.log, or press G once inside, to jump straight to the newest lines.
  • Set sensible defaults once. Put export LESS="-iRFX" in your ~/.bashrc so search ignores case and colours display correctly everywhere.
  • Use F instead of leaving and running tail -f. You can stop with Ctrl-C and scroll back through what streamed by.
  • Reach for the manual without hesitation. The help screen and manual are one keystroke away.
$ man less        # the full manual page
$ less --help     # a quick summary of options
      # inside less, press  h  for the command help screen
Back to top

9. Common Mistakes

9.1 Three Common Myths

MythReality
"less only goes forward, like more." Being able to scroll backward is the whole reason it exists.
"You edit a file in less." It is read-only. Press v to open the file in a real editor.
"less loads the whole file first." It reads only as far as you scroll, so huge files open instantly.

9.2 Other Traps to Avoid

  • Forgetting how to quit. Press q. Not Ctrl-C, not Ctrl-Z. If you pressed Ctrl-Z by accident and the shell seems stuck, type fg to bring less back.
  • Seeing colour codes as noise. If output looks like ESC[0m junk, add -R: for example git log | less -R.
  • Jumping to G on live input. Pressing G on standard input forces less to read all the way to the end, which can hang on an endless stream. On a normal file it is fine.
  • Expecting a search to match different case. Without -i, /error will not find ERROR. Start with less -i or set it in the LESS variable.
  • Using cat file | less. It works, but you can just write less file. Save the pipe for output that is not already a file.
Back to top

10. Summary

The less command is how you actually read what Linux shows you, from a config file to a live log.

  • less is a pager: it shows text one screen at a time and lets you move both forward and backward.
  • Its name is a pun. It is the "opposite of more", the older pager that could only scroll forward. Mark Nudelman wrote it in 1984.
  • It is read-only and safe, and it opens huge files instantly because it does not read them all up front.
  • Move with Space, b, j, k, g, and G. Quit with q. Get help with h.
  • Search with / and ?, repeat with n and N. The pattern is a regular expression.
  • Useful options: -N (line numbers), -i (ignore case), -S (chop long lines), -R (show colours), and -F plus -X for short files.
  • Press F to follow a growing file like tail -f, then Ctrl-C to scroll back and search it.
  • It reads inside compressed files through lesspipe, and it is the viewer behind man, git, and systemctl.
  • When in doubt, type man less, or press h while inside it.

This is the quick reference worth keeping:

less FILE        open a file in the pager
Space / b        page forward / backward
j / k            one line down / up
g / G            jump to start / end of file
/text            search forward   (n = next, N = previous)
?text            search backward
-N               show line numbers
-i               case-insensitive search
-S               chop long lines instead of wrapping
less -R          keep colours (git, grep --color)
less +F FILE     follow a growing log, like tail -f
q                quit

Once less feels natural, reading a Linux system stops being a fight with scrolling text and becomes a calm, searchable activity. If your servers are producing logs you would rather have someone read, understand, and act on, that is exactly the kind of work I help with.

Back to top
Linux command: less
Peter Martin
Peter Martin
Joomla Specialist

Peter is a Joomla specialist and a Linux admin for fast, secure and scalable websites.