less (Unix)

From Wikipedia, the free encyclopedia

Less

Less output in a x-terminal
Developed by Mark Nudelman
Latest release 418 / 2 January 2008
OS Cross-platform
Genre system utility
License dual: either GPL or BSD-like License
Website 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". 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: All the searches will be case insensitive.
  • -M: Shows browsing information.
  • -N: Shows line numbers (handy for sourcecode viewing).
  • -S: Disables line wrap (long lines can be seen by side scrolling).

[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.
  • /pattern: Search for pattern. Regular expressions can be used.
  • n: Go to next match (after a successful search).
  • N: Go to previous match.
  • mletter: Mark the current position with letter.
  • 'letter: (single quote) Return to position letter.
  • s: Save current content (got from another program like grep) in a file.
  • =: File information.
  • F: continually read information from file and follow it's end. Useful for logs watching. Use Ctrl+C to exit the mode.
  • h: Help.
  • q: Quit.

[edit] Examples

less -M readme.txt                     #Read "readme.txt".
 
file * | less                          #Easier file analysis.
 
grep -i void *.c | less -I -p void     #Case insensitive search for "void" in all .c files

[edit] External links

[edit] Variations of less