ArticleslgStudy

computer science

Less (Unix)

Less (Unix) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Less (Unix) rather than just read about it. In short: 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.

Less (Unix) — main illustration
Less (Unix) — illustration

Key takeaways

  • Less (Unix) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Less (Unix) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Less (Unix) from memory before moving on to harder problems.

Reference excerpt

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, allowing for immediate viewing regardless of file size.

History Mark Nudelman initially wrote less 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." Originally, less was developed for Unix, but it has been ported to a number of other operating systems, including MS-DOS, Microsoft Windows, OS/2, and OS-9, as well as Unix-like systems such as Linux. It is still maintained today by Nudelman. 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".

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 lesspipe.sh extension can automatically determine file types such as PDF, multimedia, and compressed archives, and automatically determines which program to launch display the file's information with, such as text from a PDF file, metadata of photos, lists of files in a compressed archive, and content of a single file in a compressed archive. The command-syntax is:

less [options] [file_name]…

Frequently used options -g: Highlight just the current match of any searched string. -i: Search case-insensitively. -m: Show more detailed prompt, including file position. -N: Show line numbers (useful for viewing source code). -x3: Set tabstops (the number of columns per hard tab character) to the specified number (3, in this example) (useful for viewing source code). -S: Disable line wrapping ("chop long lines"). Long lines can be seen by side-scrolling. -X: Leave file contents on screen when less exits. -?: Show help. --follow-name: Follow mode, for log files that get replaced while being viewed.

Frequently used commands

Examples

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. 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.

See also more (command) most (Unix) pg (Unix)

References

External links Entry in Free Software Directory less(1) – FreeBSD General Commands Manual less(1) – Linux User Manual – User Commands from Manned.org less(1) – Debian General Commands Manual lesspipe.sh webpage

Illustrations

Less (Unix) illustration

Worked examples

Example 1 — a first encounter with Less (Unix)

Start with the simplest possible case. Write down what Less (Unix) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Less (Unix) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Less (Unix) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Less (Unix)

In research
Less (Unix) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Less (Unix) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Less (Unix) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Free software that uses ncurses, GNU Project software, Terminal pagers, so understanding it makes those chapters shorter.
In everyday life
Look for Less (Unix) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Less (Unix)” →

How to study Less (Unix) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Less (Unix) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Less (Unix) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Less (Unix) in simple terms?

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.

Why does Less (Unix) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Less (Unix)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Less (Unix).

Tags

  • Free software that uses ncurses
  • GNU Project software
  • Terminal pagers

Keep exploring