Home > Text Processing & Search > less

less: Freely Explore Text File Content

The less command displays the content of text files page by page and is a powerful paginator that, unlike more, allows you to freely navigate file content forwards and backwards. It is useful for efficiently reading large files or log files.

Overview

As its name 'less is more' suggests, `less` was created to overcome the shortcomings of the `more` command. While `more` can only scroll file content forward, `less` allows free movement up and down pages. It also offers powerful search functions similar to the `vi` editor and real-time file content updates (via the `F` key). `less` does not load the entire file into memory but reads only the necessary parts, allowing quick viewing of large files, even those several gigabytes (GB) in size.

Key Features

The main features of the less command are as follows:

  • Can freely scroll file content forwards and backwards.
  • Efficiently uses memory even when viewing large files.
  • Provides powerful search and navigation functions similar to vi.
  • Can monitor files with continuously added content, such as log files, in real-time.
  • Included by default in most Linux distributions.

Difference between less and more

less includes all the features of more and provides even more advanced functionalities.

  • less: Allows free scrolling of files forwards and backwards. Provides various editor-like functionalities in addition to scrolling.
  • more: Can only scroll files forward. Once content has passed, it cannot be viewed again.

Main Options

The `less` command controls output methods through various options. However, most are controlled via keyboard shortcuts in interactive mode.

1) Execution Options

2) Interactive Mode Keyboard Shortcuts

Generated command:

Try combining the commands.

Description:

`less` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Learn the features of the `less` command through various usage examples.

Explore file content

less /var/log/syslog

Freely explores the content of a large file, `/var/log/syslog`.

Use with pipe (|)

dmesg | less

Pipes the output of the `dmesg` command to `less` to view it page by page, navigating forwards and backwards.

Start from end of file

less +G /var/log/nginx/access.log

The `+G` option is useful for starting at the end of a file to immediately see the latest logs.

Output with line numbers

less -N /etc/fstab

Uses the `-N` option to output each line prefixed with its number.

Tips & Cautions

Here are some points to note when using the `less` command.

Tips

  • less uses many shortcuts similar to vi. For example, g moves to the very beginning of the file, and G moves to the very end.
  • When viewing files where content is continuously added, such as log files, open it with less and then press the F key to switch to real-time monitoring mode, similar to tail -f. To exit this mode, press Ctrl+C.

Related commands

These are commands that are functionally similar or are commonly used together.



Same category commands