
More vs. Less in Linux: The Ultimate Guide to Viewing Files
When working in the Linux command line, viewing the contents of large files can quickly clutter your terminal. A long configuration file or a verbose log can scroll past in an instant, leaving you lost. To solve this, Linux provides powerful utilities called “pagers,” which display content one screen at a time. The two most common pagers are the more
and less
commands.
While they sound similar, their capabilities are vastly different. Understanding the distinction between them is key to working efficiently in the terminal. Let’s break down each command to see which one you should be using.
Understanding the more
Command: A Look at the Classic Pager
The more
command is one of the original Unix pagers. Its function is straightforward: it displays text from a file or standard input, pausing at the end of each screen. You can then advance to the next page, but that’s where its functionality largely ends.
The defining characteristic of more
is its forward-only navigation. Once you have scrolled past a section of the text, you cannot go back. This limitation is a significant drawback when analyzing complex files.
How to Use more
:
To view a file, simply type:
more /path/to/your/file.txt
Key Navigations in more
:
- Space Bar: Moves forward one full screen.
- Enter Key: Moves forward one line at a time.
- /[text]: Searches for the first occurrence of the specified text.
- q: Quits the viewer.
While simple, the inability to scroll backward makes more
less practical for anything beyond a quick, linear review of a file.
Enter less
: Why It’s More Than more
The less
command was developed later as a powerful successor to more
. The name itself is a play on the original, humorously suggesting that “less is more.” And in terms of features, it truly delivers.
The single most important advantage of less
is its ability to scroll both forwards and backwards. You are not restricted to linear viewing; you can freely navigate throughout the entire file, making it ideal for examining log files, source code, or lengthy outputs from other commands.
Furthermore, less
is more efficient. Unlike more
, which loads the entire file into memory before displaying it, less
starts displaying the file immediately by only loading the portion you are currently viewing. This makes it significantly faster when opening very large files.
How to Use less
:
The syntax is identical to more
:
less /path/to/your/large_file.log
Key Navigations in less
:
- Space Bar / Page Down: Moves forward one full screen.
- Page Up / b: Moves backward one full screen.
- Arrow Keys (Up/Down): Scrolls one line at a time in either direction.
- /[text]: Searches forward for the specified text. Press
n
to find the next occurrence. - ?[text]: Searches backward for the specified text. Press
n
to find the next occurrence. - G: Jumps to the end of the file.
- g: Jumps to the beginning of the file.
- q: Quits the viewer.
Head-to-Head Comparison: The Key Differences
| Feature | more
Command | less
Command |
| :— | :— | :— |
| Navigation | Forward scrolling only | Forward and backward scrolling |
| Performance | Loads the entire file into memory | Loads content as needed, making it faster for large files |
| Searching | Basic forward search | Advanced forward and backward search, highlighting results |
| Features | Minimal features | Line numbers, horizontal scrolling, and more |
| Use Case | Quick, simple file viewing | In-depth file analysis and navigation |
Actionable Advice: The Power of Piping
One of the most powerful uses for less
is pairing it with other commands through a pipe (|
). When a command produces a large amount of output, you can “pipe” it into less
to view it in a manageable, searchable way.
For example, to view a list of all running processes on your system without it flying by, use:
ps aux | less
To search through your system logs for a specific error, you could use:
dmesg | less
This allows you to navigate and search the output just as you would with a regular file.
The Verdict: Why less
Is Almost Always the Better Choice
While the more
command might be present on older systems and is fine for a quick glance, the less
command is superior in almost every way. Its ability to scroll backward, search efficiently, and handle large files without performance degradation makes it an indispensable tool for any Linux user.
For modern systems and workflows, there is little reason to use more
. By making less
your default file viewer in the terminal, you’ll gain a significant boost in productivity and control when navigating the command line. Mastering less
is a simple step that pays huge dividends in efficiency.
Source: https://infotechys.com/more-vs-less-command-in-linux/