|Home||FAQ||Download||Bugs and Enhancement Requests||Mailing List|
stty: TCGETS: Operation not supported on socket"?
Less is a pager.
A pager is a program that displays text files.
Other pagers commonly in use are
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.
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:
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.
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.
Less was written by Mark Nudelman and is currently being maintained by him. You can write to him at firstname.lastname@example.org.
Please use https://github.com/gwsw/less/issues to report bugs.
The old list of bugs will be removed when all open bugs from that list have been entered into github.
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.
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".
/*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 "
less +F ...".
lesskeyprogram lets you change the meaning of any key or sequence of keys. See the lesskey man page for details.
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
LESSenvironment variable is set to "
-IE", every time you run less it will do case-less searches and quit at end-of-file.
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.
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.
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
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),
LESSCHARSET to "utf-8".
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:
If a filename begins with a dash or a plus sign, you can't just say
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
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.
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.
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.
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.
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.
stty: TCGETS: Operation not supported on socket"?
If you see this message and you're using csh, you probably have
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.
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.
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.
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
There appears to be a bug in the Linux 2.6.9 release
/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
This causes less to exit immediately after displaying
the first page of the output.
Reportedly, upgrading to the latest
will fix this.
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.
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.