less (Unix)

From Wikipedia, the free encyclopedia
Jump to: navigation, search
less
Less.jpg
less output in an x-terminal
Developer(s) Mark Nudelman
Stable release 444 / June 9, 2011; 8 months ago (2011-06-09)
Preview release 441 / February 28, 2011; 11 months ago (2011-02-28)
Operating system Cross-platform
Type system utility
License dual: either GPL or BSD-like License
Website http://www.greenwoodsoftware.com/less/

less is a terminal pager program on Unix, Windows, and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to more, but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers, less does not need to read the entire file before starting, resulting in faster load times with large files.

Contents

[edit] History

less was initially written by Mark Nudelman during 1983-85, in the need of a version of more able to do backward scrolling of the displayed text. The name came from the joke of doing "backwards more." To help remember the difference between less and more, a common joke is to say, "less > more," implying that less has greater functionality than more. A similar saying is that "less is more, more or less". less is now part of the GNU project and it is included in most Unix systems.

[edit] Usage

less can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While less is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both more and vi. It is also possible to search for character patterns in the file.

By default, less displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.

The command-syntax is:

less [options] file_name

[edit] Frequently used options

  • -g: Highlights just the current match of any searched string.
  • -I: Case-insensitive searches.
  • -M: Shows more detailed prompt, including file position.
  • -N: Shows line numbers (useful for source code viewing).
  • -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
  • -?: Shows help.

[edit] Frequently used commands

  • [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
  • [Space bar]: Next page.
  • b: Previous page.
  • ng: Jump to line number n. Default is the start of the file.
  • nG: Jump to line number n. Default is the end of the file.
  • /pattern: Search for pattern. Regular expressions can be used. [/ = slash] Press / and then Enter to repeat the previous search pattern. Press ESC and then u to undo search highlighting.
  • n: Go to next match (after a successful search).
  • N: Go to previous match.
  • mletter: Mark the current position with letter.
  • 'letter: Return to position letter. [' = single quote]
  • '^ or g: Go to start of file.
  • '$ or G: Go to end of file.
  • s: Save current content (got from another program like grep) in a file.
  • = or Ctrl+g: File information.
  • F: continually read information from file and follow its end. Useful for logs watching. Use Ctrl+c to exit this mode.
  • -option: Toggle command-line option -option.
  • h: Help.
  • q: Quit.

[edit] Examples

less -M readme.txt                     # Read "readme.txt."
less +F /var/log/mail.log              # Follow mode for log
file * | less                          # Easier file analysis.
less -I -p void *.c                    # Case insensitive search for "void" in all .c files

[edit] Memory considerations

The --buffers=n and --auto-buffers options control how much memory less may use to buffer inputs. This is most relevant when less is directly accessing a named file that is modified or deleted while less is still running, and when less is receiving data from a pipe and the data can not be randomly accessed or regenerated. In these situations, anything not buffered can not be redisplayed or searched by less. On the other hand, unlimited buffering means that less will request as much memory as it is fed data, which could drive the system into using virtual memory and swapping a lot of data between RAM and disks (dramatically slowing system performance for most applications on the host), or even further into memory exhaustion where any application on the host requesting memory may have that request denied, or may crash when attempting to access memory that the OS promised but can't find when the application actually attempts to use it and a page-fault occurs. For this reason, some companies/organisations insist that less be used only with fixed buffering - or not at all - on production machines.[citation needed]

[edit] Variations

[edit] See also

[edit] External links

Personal tools
Namespaces
Variants
Actions
Navigation
Interaction
Toolbox
Print/export
Languages