Less FAQ

Home FAQ Download Bugs and Enhancement Requests Mailing List

Frequently Asked Questions about less

Table of Contents

  1. Overview
    1. What is less?
    2. Why would I want to use less?
    3. Where did less come from?
  2. Resources
    1. How can I get a copy of less?
    2. How can I write to the author of less?
    3. What if I find a bug in less?
  3. Technical questions
    1. Cool less tricks
    2. I can't get less to build!
    3. Do I need Unix to use less?
    4. Can less display non-English language characters?
    5. Why does less scroll off the screen if there are long lines?
    6. How can I view a file whose name looks like a command line option?
    7. Why does -r cause display problems?
    8. Why is the first line on the screen highlighted?
    9. Can less leave the screen alone when it quits?
    10. Why doesn't less quit when it reaches the end of the file?
    11. Why doesn't less quit when I type control-C?
    12. Why does it take so long to start the editor / start a shell?
    13. Why does it say "stty: TCGETS: Operation not supported on socket"?
    14. Why are there problems if my .cshrc, .profile or ENV files produce output?
    15. Can less view compressed files?
    16. Why do I get a segmentation fault if I search for a pattern containing "\<"?
    17. Why doesn't less work with Linux 2.6.9?
    18. Why does the -p option take a pattern?
    19. Why are there no dots in the version number?
This FAQ is Copyright ©2007 by Mark Nudelman. This document may be reproduced freely, provided it is kept in its entirety and in its original format.

Questions and Answers

What is less?

Less is a pager. A pager is a program that displays text files. Other pagers commonly in use are more and pg. Pagers are often used in command-line environments like the Unix shell and the MS-DOS command prompt to display files. Windowed environments like the Windows and Macintosh desktops don't need pagers as much, since they have other methods for viewing files.

Less is not an editor. You can't change the contents of the file you're viewing. Less is not a windowing system. It doesn't have fancy scroll bars or other GUI (graphical user interface) elements. It was designed to work on simple text-only terminals.

Less has been used by thousands of people around the world since its release in 1985.

Why would I want to use less?

If you're not using a pager now, then you probably don't need less. But if you're using another pager, you should take a look at less. Less has some very nice features:

Backwards movement
It's hard to believe some people are still using pagers that don't let you move backwards in the file. Even pagers that do let you move backwards often don't work when viewing "standard input"; that is, data that is being piped into the pager from another program.
Searching and highlighting
Less lets you search for text in the file you're viewing. You can search forwards and backwards. Furthermore, less highlights the text that matches your search, to make it easy to see where the match is.
Multiple files
Less allows you to switch between any number of different files, remembering your position in each file. You can also do a single search which spans all the files you are working with.
Bold and underline
Some text files, notably Unix-style "man pages", use overstriking (backspaces) to simulate underlined and bold text. Less interprets this overstriking and displays the text in real underlined or bold mode.
Advanced features
Less has a large number of fancy features for advanced users. Once you learn the basics, you'll find you can customize less to do almost anything you want it to do. You can change key bindings, set different tab stops, set up filters to view compressed data or other file types, customize the prompt, display line numbers, use "tag" files, and more.
Portability
Less is available on many different machines, different system architectures, and different terminals. Pretty much wherever you go, you'll find less. You won't have to learn how to use a different pager on every system you use.

Where did less come from?

Back in 1983, I was working for a now-defunct company called Integrated Office Systems. Some of our software ran on a Unix system and produced enormous log files of its transactions. We wanted to be able to search these log files for error messages. But the version of "vi" we were using couldn't handle files larger than a certain size, and our log files often exceeded that size. So we were forced to use "more" to view the files. The problem was, once we found an error message, what we really wanted to see was the transactions leading up to the error; that is, the lines in the log file immediately before the error message. But more didn't allow backward movement in the file.

We often complained about this problem. We said we needed a "backwards more"; someone (it wasn't me, but unfortunately I don't remember who it was) coined the name "less" as a joke on the concept of a "backwards more". It didn't seem to me that it would be too difficult to write a simple pager that would allow forward and backward movement. I wrote the first version in late 1983 and we began using it internally. I continued to enhance it and finally decided it was a useful enough tool that I should make it available to the world. I posted the first version to the newsgroup called (at that time) net.sources in May, 1985.

Making the program publicly available allowed an enormous number of people to use it. Many people have made their own modifications and donated them to me for incorporation into the official version, and many more have reported bugs they've found or made suggestions about features they'd like to see added. This was my first experience with the concept of what is now called "open source" or "free software", and it has, I believe, produced a very high quality product. I'd like to thank all the users of less for their invaluable comments and suggestions over the years. Less wouldn't be what it is today without you.

How can I get a copy of less?

You can download a copy of less from here.

Less is also distributed as a part of the standard software available with many varieties of Unix and similar systems. Less is also available from many ftp sites, including the GNU archives on ftp.gnu.org/gnu/less.

How can I write to the author of less?

Less was written by Mark Nudelman and is currently being maintained by him. You can write to him at markn@greenwoodsoftware.com.

What if I find a bug in less?

Please use https://github.com/gwsw/less/issues to report bugs.

Cool less tricks

New users of less sometimes find that less doesn't behave exactly the way they expect. If this is the case, don't despair. Less has an enormous number of options (perhaps too many) which let you change the way it behaves. Chances are, there is a way to make less do what you want. A complete description of all these features is in the less man page, but here's a summary of some of the more popular ones.

Quit at end-of-file
To make less automatically quit as soon as it reaches the end of the file (so you don't have to hit "q"), set the -E option.
Verbose prompt
To see a more verbose prompt, set the -m or -M option. You can also design your own prompt; see the man page for details.
Clear the whole screen
To make less clear and repaint the screen rather than scrolling when you move to a new page of text, set the -C option.
Case-less searches
To treat upper-case and lower-case letters the same in searches, set the -I option.
Start at a specific place in the file
To start at a specific line number, say line 150, use "less +150 filename". To start where a specific pattern first appears, use "less +/pattern filename". To start at the end of the file, use "less +G filename".
Scan all instances of a pattern in a set of files
To search multiple files, use "/*pattern" instead of just "/pattern". To do this from the command line, use "less '+/*pattern' ...". Note that you may need to quote the "+/*pattern" argument to prevent your shell from interpreting the "*".
Watch a growing file
Use the F command to go to the end of the file and keep displaying more text as the file grows. You can do this from the command line by using "less +F ...".
Change keys
The lesskey program lets you change the meaning of any key or sequence of keys. See the lesskey man page for details.
Save your favorite options
If you want certain options to be in effect whenever you run less, without needing to type them in every time, just set your "LESS" environment variable to the options you want. (If you don't know how to set an environment variable, consult the documentation for your system or your shell.) For example, if your LESS environment variable is set to "-IE", every time you run less it will do case-less searches and quit at end-of-file.

I can't get less to build!

There are a number of possible reasons why less may not be building on your system. If you're building on a Unix system, and you ran "sh configure" once, you might try removing the "config.log" and "config.cache" files and trying it all from scratch again; that is, run "sh configure" again.

If that doesn't help and you're still stumped, send email to the author describing your problem. If possible, include the messages produced by the configure and/or make procedures.

Do I need Unix to use less?

Less was originally developed for Unix, but has been ported to a variety of other systems, including MS-DOS, Windows, OS/2, and OS-9, as well as Unix variants like Linux, FreeBSD and Solaris. See the download page for a list of supported systems.

Can less display non-English language characters?

Less has two ways to display non-English characters. If your system uses a non-ASCII single-byte character set, you should set up your system with the correct "locale" settings. If your system does not support setlocale, you can set the LESSCHARSET or LESSCHARDEF environment variable to tell less what language you are using. See the section "NATIONAL CHARACTER SETS" in the man page for details.

If your system supports the UTF-8 encoding of Unicode for non-ASCII text, as many modern systems do, you should either set your locale to something that includes the string "UTF-8" or "UTF8" (either uppercase or lowercase is ok), or set LESSCHARSET to "utf-8".

Why does less scroll off the screen if there are long lines?

If you see data scroll off the screen when you view lines longer than the screen width, something is wrong. There are two likely possibilities. First, you may be using the -r option (either explicitly or in your LESS environment variable). The man page states that the -r option may cause display problems (see Why does -r cause display problems? for more details). The other possibility is more difficult to diagnose: you may have a mismatch between your termcap or terminfo setup and the type of your terminal. On most systems, you should check that:

How can I view a file whose name looks like a command line option?

If a filename begins with a dash or a plus sign, you can't just say
less -funnyfile
because less will think the name is a command line option. The best way to view such a file is to use "--" to mark the end of the real options (if any):
less -- -funnyfile

Why does -r cause display problems?

Less needs to keep track of where the cursor is on the screen as it displays text, so that it knows when it reaches the end of the line. If the screen is 24 lines high, less wants to display enough text to exactly fill those 24 lines. To do this, it needs to know when it reaches the end of a line on the screen. But if it just starts outputting raw control characters (like ESC), it won't be able to keep track of this. For example, if less outputs four ordinary characters, it moves the cursor four spaces to the right. But on a vt220 terminal, if less outputs the four characters "ESC [ 1 m", it merely switches the terminal to "bold", but doesn't move the cursor. On the other hand, if it outputs "ESC [ 1 H", it moves the cursor to the top left corner of the screen! Obviously less would need to know what every escape sequence does to the particular terminal being used, which is not practical. So by default less does not output ESC or other control characters, to avoid this problem. When -r is set, it does output control characters, but then it is no longer possible to determine when the text wraps to a new line on the display, so the display may not be accurate in all cases.

One reason you might be using -r is to "pass through" the escape sequences that change the color of text. You can use -R instead of -r to pass through these color escape sequences, and less will understand that such sequences don't move the cursor.

Why is the first line on the screen highlighted?

You probably have the -w flag set in your LESS environment variable or in your lesskey file. The meaning of the -w flag changed in version 346. Previously it turned off the tildes displayed after end-of-file, now it highlights the first unread line on each new screen. Use the -~ flag to turn off tildes.

Can less leave the screen alone when it quits?

When less starts, it sends the "ti" termcap string to the terminal, and when it quits, it sends the "te" string. Exactly what the "te" string does depends on the system you are using, the type of terminal, and your version of termcap. On some systems, it does nothing; on others it restores the screen to the state it was in when less started, thus erasing from the screen the last page of the file which less was viewing.

If you don't like the behavior of "te" on your system, you can disable the sending of the "ti" and "te" strings by invoking less with the -X option. Unfortunately, this sometimes has other side effects, because the "ti"/"te" strings might do other things that are required. For example, on some terminals, disabling "ti" and "te" causes arrow keys to cease to function.

On less version 599 and later versions, another way to ensure that the last page displayed by less is visible after quitting is to use the --redraw-on-quit option. This redraws the last screen after sending the "te" string.

If you want "te" to do something different (for example, restore the screen if it's not doing that already), you'll have to figure out how to change the termcap or terminfo for your terminal on your system. This is done differently on different systems, so you'll have to check the documentation for your system.

Why doesn't less quit when it reaches the end of the file?

Normally, less doesn't quit until you type "q". You can make it quit as soon as it reaches the end of the file by using the -E option. However, many (but not all) people prefer to have less remain active until they explicitly quit, because they might wish to back up and look at earlier parts of the file again.

Why doesn't less quit when I type control-C?

Control-C on Unix systems is an "interrupt" character; it is supposed to stop whatever the current program is doing. Many programs react to control-C by just quitting. But in many interactive programs, such as less and vi, control-C stops whatever the program was doing and returns the program to an "idle" state, where it's just waiting for a command. For example, in less you can use control-C to stop a long search, or to stop the F command, without quitting the program. If you really want to quit, just type "q". If you really really want control-C to cause less to quit, you can use the -K option.

Why does it take so long to start the editor / start a shell?

If you use csh, you may find it takes a long time to start a shell (using the "!" command) or to start an editor (using the "v" command). This is usually because your .cshrc file contains many commands. Csh executes the commands in .cshrc each time less starts a subshell. If you only need these commands executed once at login, and not in every subshell, you can move them to .login instead of .cshrc. Changing your SHELL environment variable to "sh" can also avoid this problem, although you will then be using sh rather than csh in programs that use the SHELL variable. You can also try setting SHELL to "csh -f", which tells csh not to execute the .cshrc or .login files.

Why does it say "stty: TCGETS: Operation not supported on socket"?

If you see this message and you're using csh, you probably have a "stty" command in your .cshrc file. You should either move this to your .login file so it only gets executed once, when you login; or set your SHELL variable to "csh -f", which tells csh not to execute the .cshrc or .login files.

Why are there problems if my .cshrc, .profile or ENV files produce output?

Like some other programs, less invokes the shell to perform certain operations, such as expanding special characters in filenames. It does this by invoking a shell program and reading the program's output. If the shell itself produces output, this interferes with the output coming from the program that less is trying to read from. This problem is not unique to less; for example, if you have your shell set up to produce output from a .cshrc or ENV file and then you try the command ":n *.c" from within vi, you'll see a similar problem.

If you use the LESSOPEN feature, having your shell produce output can cause other problems. Since less uses the shell to invoke the LESSOPEN filter, the output from the shell will appear at the beginning of the output from the filter program, causing it to appear to be part of the file.

In general, it's not a good idea for a .cshrc or ENV file to produce output. If you use csh, tcsh or a variant, you can move the output commands to your .login file so they only get executed once, when you login; or set your SHELL variable to "csh -f", which tells csh not to execute the .cshrc or .login files. If you use sh, ksh, bash or a variant, you can move the output commands from your ENV file to your .profile file so they only get executed once when you login. Unfortunately, some older versions of these shells execute the .profile every time a shell is invoked rather than only at login. For such shells, it is best to avoid output in the .profile, or arrange for the output to appear only at login time in some other way.

Can less view compressed files?

Less provides a mechanism to preprocess the file being viewed. The preprocessing can decompress a compressed file, or do other arbitrary processing on the file contents. However, each user must specify their own preprocessor. See the INPUT PREPROCESSOR section of the man page for more details. Less does not provide any default preprocessing, because the types of compressed files likely to be viewed depends on the work habits of the particular user. In a future release of less, some automatic preprocessing may be provided.

Why do I get a segmentation fault if I search for a pattern containing "\<"?

Less usually uses the pattern matching library supplied by the operating system on which it runs. This pattern matching library is sometimes called the "regular expresson library". There is a bug in some regular expression libraries which sometimes causes the program to crash if you search for a pattern that includes a backslash followed by a less-than sign. This bug seems to be in glibc 2.2.2, and possibly other versions. It is known to exist in several versions of Linux. Less has a built-in regular expression library which does not have this bug; if you wish to use it, compile with
configure --with-regex=regcomp-local

Why doesn't less work with Linux 2.6.9?

There appears to be a bug in the Linux 2.6.9 release which causes /dev/tty to be created as a directory instead of a character file as it should be (it appears that /dev/pty was inadvertently renamed to /dev/tty). This causes less to exit immediately after displaying the first page of the output. Reportedly, upgrading to the latest udev package will fix this.

Why does the -p option take a pattern?

The -p option was added long ago, in 1985, in a half hearted attempt to be compatible with the then-emerging POSIX standard for "more (1)". At that time, the draft POSIX specification said that the parameter to the -p option should be a search pattern. This seemed overly restrictive to me. Less had the "+command" option syntax to allow an arbitrary command, not just a pattern, to be passed in. I thought that the POSIX spec should specify this behavior for more's -p option. I believe that I wrote a comment to the POSIX committee to this effect, but I'm not sure. In any case, I implemented the -p option the way the spec was written. Meanwhile, at some point the POSIX spec was changed to make the parameter to -p indeed be an arbitrary command, but I was not aware of this for some time. When I became aware of this, in 2005, I changed the -p option to take a command when less is run in more-compatible mode. I left it as a search pattern when not run in more-compatible mode, to avoid unnecessary disruptions to users who may have been accustomed to the previous behavior in non-more-compatible mode.

Ironically, in the Rationale section of the POSIX spec, it says

In early proposals, [the -p option] took a pattern argument, but historical less provided the more general facility of a command.
So while I changed less to match the (original) spec, the spec was changed to match what less was originally doing, The strange result of all this is that the behavior which I preferred (arbitrary command) appears only when less is run in more-compatible mode, while the behavior that was proposed by the POSIX more spec (search pattern) appears when less is run in non-more-compatible mode.

Why are there no dots in the version number?

I use a very simple version numbering scheme. The first version of less was version 1. The next was version 2. And so on. There are no "major" and "minor" releases, so there are no dots in the version number. So version 381 is the three hundred and eighty-first version of less. It's just 381, not 3.81 or 3.8.1.