The Full Wiki

Less (Unix): Wikis

Advertisements

Note: Many of our articles have direct quotes from sources you can cite, within the Wikipedia article! This article doesn't yet, but we're working on it! See more info or our list of citable articles.

Encyclopedia

(Redirected to less (Unix) article)

From Wikipedia, the free encyclopedia

less
Less.jpg
less output in an x-terminal
Developer(s) Mark Nudelman
Stable release 436 / 25 July 2009
Operating system Cross-platform
Type 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

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.

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
Advertisements

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.

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.
  • 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.
  • =: 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.

Examples

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

Variations of less

See also

External links


Advertisements






Got something to say? Make a comment.
Your name
Your email address
Message