March 30, 2023

Start using (the programme) less” to display files

You don’t have to open files or documents to display them.

You can use the programme called less”.

Less is a pager. A pager is a program that displays text files1.

In the terminal run:

$ less file

To quit less press q.

To navigate the file viewed use keys:

  • j to scroll down
  • k to scroll up
  • f or space bar to scroll down one window size
  • b to scroll up one window size

The idea of using keys rather than the arrow-key pad (to the bottom right of your keyboard) is that it is faster since your right-hand fingers are already positioned on keys j and k. Once one gets use to scroll up and down with j and k it becomes inconvenient to use the arrow keys.

To return to the top of the page press g.

To jump to the bottom of the page press GG.

Searching for keywords

You can search for keywords by typing /some_keyword. Once the keyword is highlighted, press return (enter). Now you can move to the next occurrence by pressing the key n (small cap), and the previous occurrence by pressing the key N (large cap).

If you already scrolled down and think that the keyword you are looking for is towards the top of the page, use the inverse” of /, that is: ?. For example ?some_keyword to search backwards.

Switch to a text editor to edit a file

If you want to edit the file you are previewing press v.

Display multiple files with less

You can preview multiple files running:

$ less file1 file2 file3

To navigate between files press:

  • :n to examine the next file
  • :p to examine the previous file

Use less to display the output of other commands

You can use less to display the output of other commands instead of having the output of a command printing in the shell (i.e., the terminal).

For example, to list all pdf files of a directory and pipe the output of ls to less run:

$ ls .*pdf | less

That way you can navigate the (supposedly long) list using the keys j and k or search for keywords using /.

| pipes the output of the command preceding | as input to the next.

* acts as wild card (a substitute) for one or many characters (“a string”, esoterically speaking). In that example above, that is all files ending in .pdf.

The history of less

Less was written by Mark Nudelman in 1983-85, released in 1984 and currently maintained by him2. Less is released under GNU GENERAL PUBLIC LICENSE Version 3.

Learn more

To learn more about less, run $ man less to view less’s manual (in less).


  1. https://www.greenwoodsoftware.com/less/faq.html#what↩︎

  2. https://www.greenwoodsoftware.com/less/faq.html#mail↩︎


personal computing less command-line interface (cli) start using gnu linux trisquel wiki office applications text processing shell literacy

No affiliate links, no analytics, no tracking, no cookies. This work © 2016-2024 by yctct is licensed under CC BY-ND 4.0 .   about me   contact me   all entries & tags   FAQ   GPG public key

GPG fingerprint: 2E0F FB60 7FEF 11D0 FB45 4DDC E979 E52A 7036 7A88