Linux has a rich set of command-line tools for text manipulation, and one of the
most commonly used commands for viewing text files is
is a terminal pager program that allows you to view large files in a way that is
faster, more efficient, and more feature-rich compared to other text viewing
more. This article delves into the details of
less command and explores its functionalities, options, and use-cases.
The simplest way to use
less is to open a file for viewing:
This will display the content of
filename.txt one screen at a time. You can
navigate through the file using your keyboard. For example, pressing the
key scrolls down, while
b scrolls back up. Press
q to quit and return to the
When you open a file with
less, various keyboard shortcuts are available to
navigate through the file:
|Keystroke||Description||Example or Additional Details|
|Help screen||Shows all commands within |
|Forward one screen||Scrolls down one screen|
|Backward one screen||Scrolls up one screen|
|Forward one screen||Equivalent to |
|Backward one screen||Equivalent to |
|Forward one line||Scrolls down by one line|
|Backward one line||Scrolls up by one line|
|Forward half screen||Scrolls down half a screen|
|Backward half screen||Scrolls up half a screen|
|Go to end||Jumps to the end of the file|
|Go to start||Jumps to the start of the file|
|Go to a specific percentage|
|Go to specific line number|
|Repeat last search (forward)|
|Repeat last search (backward)|
|Forward forever (like |
|Clear screen||Refreshes the screen|
|Set a mark|
|Go to a mark|
|Go to a mark on the same line|
|Show line numbers||Displays the current line numbers|
|Show version||Shows the version of |
|Backward one line||Equivalent to |
|Forward one line||Equivalent to |
|Left scroll||Scrolls text to the left|
|Right scroll||Scrolls text to the right|
This table should now give a comprehensive overview of the keyboard navigation possibilities within the
More about the Commands
space: When you're reading a large file, scrolling down one screenful at a time lets you read through the content in a controlled manner. This prevents you from having to manually scroll, making it easier to maintain your reading focus.
b: The ability to scroll back is what distinguishes
more. If you realize that you've missed something important, the
bcommand is invaluable for going back and reviewing content.
g: Jumping to the beginning of a file is extremely useful when you're deep within a large document and you quickly want to go back to the start, without having to repeatedly press keys to scroll back.
G: The counterpart to
g, this command lets you quickly jump to the end of a file. It's particularly useful when you are searching for information that you know is near the end of a file.
/pattern: Searching is one of the key strengths of
less. You don’t have to manually scroll through thousands of lines. Just type
/followed by the pattern you are looking for, and
lesswill navigate to the next instance of this pattern.
?pattern: Sometimes, you realize that the information you are looking for was actually before the current position in the document. Use
?followed by the pattern to search backwards through the document.
n: Once you've initiated a search, pressing
nwill continue that search and take you to the next occurrence of the pattern. This is a powerful way to navigate through search results without having to retype the search term.
N: If you've been searching in one direction and want to reverse your direction,
Nlets you do that easily. This can be particularly useful when you've reached the end of the document and want to check for other occurrences in the opposite direction.
Understanding how to navigate with
less effectively can make your text file
exploration much more efficient. The command offers a range of features to help
you quickly find and view the information you need.
As noted above, you can search within the file. This can be especially useful
when viewing log files or code. Simply use
/ followed by the pattern to search
? to search backward.
You can view line numbers by typing
-N while you're inside the
This is especially useful if you're looking at a code file and want to reference
Viewing Multiple Files
You can open multiple files by passing their names:
less file1.txt file2.txt
Navigate between files using
:n for the next file and
:p for the previous
less has a plethora of options to tailor its behavior:
-S: Chop long lines instead of wrapping them.
-m: Display more verbose prompt.
-E: Automatically exit if the end of the file is reached.
Check System Logs
Check Configuration Files
Combine with Other Commands
You can pipe the output of another command to
lessfor easier viewing.
dmesg | less
View Compressed Files
You can also view compressed files directly:
less command was actually derived from the
more command in Unix.
more command also allows you to view text files one screen at a time.
less offers more features and is generally more versatile.
The primary difference lies in navigation. In
more, once you scroll down, you
can't scroll back up again. This is where
less improves upon
more — it
allows for both forward and backward navigation. The name
less is a bit of a
joke, suggesting that 'less is more' because it provides more functionality
more while offering a similar user experience.
less is an incredibly useful command in the Linux toolkit, giving
users a powerful way to navigate and manipulate text right from the command
line. It is an indispensable tool for anyone who works in a Linux environment.
Level Up Your TypeScript And Object Oriented Programming Skills. The only complete TypeScript course on the marketplace you building TypeScript apps like a PRO.SEE COURSE DETAILS
What Can You Do Next 🙏😊
If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for ssoftware developers.