VMware ESXi and vSphere Cluster Management
Using the less Text Viewer in Linux
Learn how to open files with less, navigate screen by screen or line by line, search text, jump to a line, read status information, and exit to the Linux shell.
What is less?
less is a Linux terminal pager. A pager presents text in screens or pages and lets you move interactively through the content.
Use less when you want to read a text file incrementally instead of displaying the entire file at once or opening it in an editor. It is useful for logs, configuration files, source code, command output, and other text content that is longer than one terminal screen.
less is primarily a viewing and navigation tool. Although it provides some interactive commands, it is not intended for ordinary text editing. Use an editor such as nano when you need to change and save a file.
Opening a file with less
At a shell prompt, provide the filename after the less command:
less filename
For example:
less /var/log/example.log
The file opens inside an interactive viewing mode in the terminal. The first screen of content is displayed, and the shell prompt is temporarily replaced by the less interface. Press navigation keys to read more, then press q to leave it.
less can also display command output. A pipe sends the output of one command to less:
some-command | less
This is helpful when a command produces more output than fits on the screen.
Understanding the less status line
The bottom area of the less display is the status line. It reports your position in the file. Its exact formatting can vary, but it commonly includes the filename, the currently visible line range, the total number of lines, and an approximate percentage position.
| Component | Meaning | Example interpretation |
|---|---|---|
| File name | The file currently being viewed. | notes.txt identifies the open file. |
| Visible line range | The first and last lines currently visible on screen. | lines 1-23 means the screen shows lines 1 through 23. |
| Total line count | The number of lines in the file, when available. | of 37 means the file contains 37 lines. |
| Percentage through file | An approximate indication of how far the current view is through the file. | 63% means the view is approximately 63 percent through the file. |
For example, a status indicator describing lines 1 through 23 out of 37 at 63 percent tells you which content is visible, how large the file is, and the approximate viewing position. The percentage is a position estimate and may not correspond exactly to the ratio of the first visible line to the total line count.
Essential less navigation commands
| Key or command | Action | Typical use |
|---|---|---|
Space | Move forward one screen. | Read the next page of a long file. |
f | Move forward one screen. | Use a letter key instead of Space for page movement. |
b | Move backward one screen. | Review the previous page. |
Up Arrow | Move upward by one line. | Inspect nearby content precisely. |
Down Arrow | Move downward by one line. | Read the next line without jumping a full page. |
/search-term | Search forward for text. | Find a word or phrase in a long file. |
g line-number | Jump to a specified line. | Go directly to a known location in a large file. |
q | Quit less. | Return to the shell prompt. |
Moving screen by screen
Press Space or f to move forward by approximately one terminal screen. This is page movement: many lines move at once.
Press b to move backward by approximately one screen. Use it when you have passed the section you want to review.
Screen movement is different from line movement. A screen command quickly covers a large section, while an arrow key moves only one line at a time.
Moving line by line
Press the Up Arrow key to move upward one line and the Down Arrow key to move downward one line. Line-by-line navigation is useful when you are inspecting adjacent lines, comparing nearby entries, or stopping at an exact piece of content.
If the arrow keys move too slowly through a long file, switch to Space, f, or b for screen movement.
Searching within a file
To start a forward search, press the slash character:
/search-term
In the interactive less display, press /, type the phrase you want to find, and press Enter. less moves to a matching occurrence in the viewed content.
For example, to find the word timeout:
/timeout
After pressing Enter, inspect the new location. Searching is usually faster and more reliable than manually scrolling through a long log or source file.
Jumping to a specific line
less supports a line-number argument with the g command. To go to line 250, enter the line number followed by g:
250g
This is often described as the g line-number command pattern: use g with the requested line number. The exact keystroke form in less is commonly the number first and g second. Jumping directly to a line is especially useful when an error message, test result, or editor points you to a line in a large file.
Exiting less
Press q while the less display is active:
q
less closes and returns you to the shell prompt. If you cannot type a new shell command after opening a file, you are probably still inside less; press q to quit the pager.
Using less with manual pages
A man page is built-in Linux documentation for a command, program, or system feature. The man command commonly uses less as its pager:
man command-name
For example:
man ls
The documentation opens in a less-style interactive view. You can use Space or f to move forward, b to move backward, the arrow keys to move line by line, and / to search for a topic. Press q to leave the manual page and return to the shell.
Practical walkthrough
Read a multi-page text file
- Open the file with
less report.txt. - Read the first screen and check the status line for the filename and position.
- Press
Spaceorfto move forward one screen. - Press
bif you need to review the previous screen. - Use the Up and Down Arrow keys when you need to inspect individual lines.
- Press
qto return to the shell.
Find a word in a file
- Open the file, for example with
less application.log. - Press
/. - Type a search phrase such as
error. - Press
Enterto run the search. - Read the matching location and use the navigation keys to examine nearby lines.
Go to a known line
- Open the large file with less.
- Enter a line-number command such as
250g. - Use the status display and visible content to confirm the new position.
- Press
qwhen finished.
Troubleshooting less
- You cannot return to the terminal: You are likely still inside less. Press
q. - Arrow keys do not move a full page: Arrow keys move one line at a time. Use
Spaceorffor a full screen forward, andbfor a full screen backward. - You cannot find text in a long file: Press
/, enter the desired text, and pressEnterinstead of scrolling manually. - The position is unclear: Read the status line at the bottom. Look for the filename, visible line range, total line count, and percentage indicator.
Key points to remember
less filenameopens a text file for interactive viewing.- less is a pager for reading and navigation, not an ordinary text editor.
Spaceandfmove forward by a screen;bmoves backward by a screen.- The Up and Down Arrow keys move one line at a time.
- Use
/textfollowed byEnterto search forward. - Use a line number with
g, such as250g, to jump through a large file. - Press
qto quit and return to the shell prompt. - The
mancommand commonly uses less to display manual pages.