How to Use the less Command in Linux

Less is a command-line utility that displays the contents of a file or a command output, one page at a time. It is similar to more, but has more advanced features and allows you to navigate both forward and backward through the file.
Unlike text editors like vim or nano
, less doesn’t read the entire file on startup, which results in much faster load times.
The less command is mostly used for opening large files
.
How to Use Less
The general syntax for the less program is as follows:
less [OPTIONS] filenameFor example, to view the content of the /usr/share/common-licenses/GPL-3 file you would type:
less /usr/share/common-licenses/GPL-3
You can also redirect the output from a command to less using a pipe. For example, to view the output of the ps
command page by page you would type:
ps aux | lessNavigating Through the File Content
When opening a file whose content is too large to fit in one page, you will see a single colon (:).
To go forward to the next page press either the f key or Space bar. If you want to move down for a specific number of lines, type the number followed by the space or f key.
You can press either the Down arrow or Enter to scroll forward by one line and Up arrow scroll backward by one line.
To go back to the previous page hit the b key. Move up for a specific number of lines, by typing the number followed by the b key.
If you want to search for a pattern, type forward slash (/) followed by the pattern you want to search. Once you hit Enter, less will search forward for matches. To search backward, use (?) followed by the search pattern.
When the end of the file is reached, the string (END) is shown at the bottom of the screen.
To quit less and go back to the command line press q.
Less Options
If you want less to show line numbers, launch the program with the -N option:
less -N filenameBy default, when less exits, the file contents will be cleared from the screen. To leave file contents on screen, use the -X option:
less -X filenameThe +F option tells less to watch the file contents for changes. This is useful when opening log files.
less +F /var/log/messagesWhen launched with +F, less will behave pretty much the same as tail -f
.
Less Commands
The less program includes a number of commands that allow you to navigate through the file contents and search for strings. To view a full list of all commands, type h.
Most of the commands that you can enter from the keyboard are based on those used by both more and vi. The same action can be performed using different keys.
Below are some of the most frequently used commands to navigate through the file contents when viewed by less:
Viewing Multiple Files
You can open multiple files with less by specifying them as arguments:
less file1.txt file2.txt file3.txtOnce opened, use the following commands to navigate between files:
:n- Go to the next file.:p- Go to the previous file.:e filename- Open a new file.
Marking Positions
When viewing large files, you can mark positions and return to them later. This is useful when you need to jump between different parts of a file.
To set a mark, press m followed by a lowercase letter (e.g., ma to set mark a).
To return to a mark, press ' (single quote) followed by the letter (e.g., 'a to return to mark a).
Quick Reference
For a printable quick reference, see the less cheatsheet .
| Task | Command |
|---|---|
| View a file | less filename |
| View with line numbers | less -N filename |
| Follow file changes | less +F filename |
| Search forward | /pattern |
| Search backward | ?pattern |
| Next search result | n |
| Go to end of file | G |
| Go to start of file | g |
| Quit | q |
Conclusion
We covered the less command including navigation, searching, viewing multiple files, and marking positions.
For a complete list of all options and commands, check the man less page. You may also want to look at related commands like cat
, head
, and tail
.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page