less
  1. less-commands

Commands - (Less Tutorial)

Less is a popular text editor that comes preinstalled on many Unix-based systems. It is similar to the more well-known text editor, Vim, but has a more user-friendly interface. In this tutorial, we'll cover some common commands you can use in Less.

Syntax

To open a file in Less, simply type less followed by the file name:

less filename

Once the file is open, you can use various commands to navigate and search through it.

Example

Let's say we have a file named example.txt. To view the contents of this file in Less, we can use the following command:

less example.txt

Output

The contents of the file will be displayed on the terminal screen, one page at a time. You can navigate through the file using the arrow keys, PgUp and PgDn keys, or by using the following commands:

  • j or Down Arrow: Move down one line.
  • k or Up Arrow: Move up one line.
  • f or Space Bar: Move forward one page.
  • b or Backspace: Move back one page.
  • g: Move to the beginning of the file.
  • G: Move to the end of the file.
  • /: Search for a pattern in the file.
  • q: Quit Less.

Explanation

In this example, we used the less command to view the contents of a file named example.txt. We can navigate through the file using various commands, such as the arrow keys or the f and b keys to move forward and backward one page at a time. We can search for a specific pattern using the / command, and quit the Less editor using the q key.

Use

Less can be used to view the contents of a file, search through a file, and navigate through a file quickly and efficiently. It is especially useful for viewing large files, as it only loads one page at a time, reducing the memory usage.

Important Points

  • Less is not a WYSIWYG editor, which means that any modifications made to the file cannot be saved directly from Less.
  • To exit Less without saving any changes, press q.
  • To exit Less and save any changes that were made, press :wq.

Summary

In this tutorial, we covered some common commands you can use in Less, such as opening a file, navigating through a file, searching for a pattern, and quitting the editor. These commands can help you view and navigate through files quickly and efficiently, making Less a useful tool for anyone who works with text files regularly.

Published on: