Why Less is Faster than More Command for Effective File Navigation



More is a command to view (but not modify) the contents of a text file, one screen at a time. It is available on Unix and Unix-like systems, DOS, OS/2, and Microsoft Windows. Programs of this sort are called pagers. More is a very basic pager, originally allowing only forward navigation through a file, though newer implementations which allows for limited backward movement.

The basics of more command should be like this –

$ more /var/log/dkpg.log

The sample output should be like this –

2016-12-02 11:30:45 startup archives unpack
2016-12-02 11:30:45 install python-ptyprocess:all <none> 0.5-1
2016-12-02 11:30:45 status half-installed python-ptyprocess:all 0.5-1
2016-12-02 11:30:45 status unpacked python-ptyprocess:all 0.5-1
2016-12-02 11:30:45 status unpacked python-ptyprocess:all 0.5-1
2016-12-02 11:30:46 install python-pexpect:all <none> 4.0.1-1
2016-12-02 11:30:46 status half-installed python-pexpect:all 4.0.1-1
2016-12-02 11:30:46 status unpacked python-pexpect:all 4.0.1-1
2016-12-02 11:30:46 status unpacked python-pexpect:all 4.0.1-1
2016-12-02 11:30:46 install python-simplegeneric:all <none> 0.8.1-1
2016-12-02 11:30:46 status half-installed python-simplegeneric:all 0.8.1-1
2016-12-02 11:30:46 status unpacked python-simplegeneric:all 0.8.1-1
2016-12-02 11:30:46 status unpacked python-simplegeneric:all 0.8.1-1
2016-12-02 11:30:47 install ipython:all <none> 2.4.1-1
2016-12-02 11:30:47 status half-installed ipython:all 2.4.1-1
2016-12-02 11:30:47 status triggers-pending man-db:amd64 2.7.5-1
2016-12-02 11:30:47 status triggers-pending hicolor-icon-theme:all 0.15-0ubuntu1
2016-12-02 11:30:47 status half-installed ipython:all 2.4.1-1
.........................................................................................

Cat command is as shown below –

$ cat /var/log/boot.log | more

The sample output should be like this –

[ OK ] Started File System Check on /dev/disk/by-uuid/8E9A-D511.
Mounting /boot/efi...
[ OK ] Mounted /boot/efi.
[ OK ] Reached target Local File Systems.
Starting Clean up any mess left by 0dns-up...
Starting Set console font and keymap...
Starting LSB: AppArmor initialization...
Starting Tell Plymouth To Write Out Runtime Data...
Starting Create Volatile Files and Directories...
[ OK ] Started Tell Plymouth To Write Out Runtime Data.
[ OK ] Started Clean up any mess left by 0dns-up.
Starting Nameserver information manager...
[ OK ] Started Nameserver information manager.
[ OK ] Started Set console font and keymap.
[ OK ] Created slice system-getty.slice.
[ OK ] Started Create Volatile Files and Directories.
Starting Update UTMP about System Boot/Shutdown...
Starting Network Time Synchronization...
[ OK ] Started Update UTMP about System Boot/Shutdown.
[ OK ] Started Network Time Synchronization.
[ OK ] Reached target System Time Synchronized.
[ OK ] Started LSB: AppArmor initialization.
[ OK ] Reached target System Initialization.

In order to navigate, press Enter key or press Spacebar key to navigate one page. To exit the command just press q key or CTRL+C key.To set the number of lines a page should contain,use the following command –

$ more -5 /var/log/kern.log

The above command shows only first 10 lines. The sample output should be like this –

Dec 6 12:27:33 khushboo-HP-15-Notebook-PC kernel: [ 2941.623182] nouveau
0000:09:00.0: DRM: resuming kernel object tree…
Dec 6 12:27:33 khushboo-HP-15-Notebook-PC kernel: [ 2941.740892] nouveau
0000:09:00.0: bus: MMIO write of 0000001f FAULT at 6013d4 [ IBUS ]
Dec 6 12:27:33 khushboo-HP-15-Notebook-PC kernel: [ 2941.741404] nouveau 0000:0

To get more information about more command, use the following command

$ more -h

The sample output should be like this –

more: unknown option -h
Usage:
more [options] ...
A file perusal filter for CRT viewing.
Options:
-d    display help instead of ringing bell
-f    count logical rather than screen lines
-l    suppress pause after form feed
-c    do not scroll, display text and clean line ends
-p    do not scroll, clean screen and display text
-s    squeeze multiple blank lines into one
-u    suppress underlining
- the number of lines per screenful
+ display file beginning from line number
+/ display file beginning from search string match
-V display version information and exit
For more details see more(1).

Learn Linux ‘less’ Command

Less command allows you to view the contents of a file and navigate through file. The sample of less command should be like this –

$ less /var/log/dpkg.log

The sample output should be like this –

2016-12-02 11:30:48 status half-installed ipython:all 2.4.1-1
2016-12-02 11:30:48 status triggers-pending bamfdaemon:amd64 0.5.3~bzr0+16.04.20
160701-0ubuntu1
2016-12-02 11:30:48 status triggers-pending mime-support:all 3.59ubuntu1
2016-12-02 11:30:48 status unpacked ipython:all 2.4.1-1
2016-12-02 11:30:48 status unpacked ipython:all 2.4.1-1
2016-12-02 11:30:48 upgrade libmysqlclient20:i386 5.7.13-0ubuntu0.16.04.2 5.7.16-0ubuntu0.16.04.1
2016-12-02 11:30:48 status triggers-pending libc-bin:amd64 2.23-0ubuntu3
2016-12-02 11:30:48 status half-configured libmysqlclient20:i386 5.7.13-0ubuntu0.16.04.2
2016-12-02 11:30:48 status unpacked libmysqlclient20:i386 5.7.13-0ubuntu0.16.04.2

By Enter key, You can navigate through the file line by line pressing. To get more information about less command, use the following command

$ less --help

The sample output should be like this –

SUMMARY OF LESS COMMANDS
Commands marked with * may be preceded by a number, N.
Notes in parentheses indicate the behavior if N is given.
A key preceded by a caret indicates the Ctrl key; thus ^K is ctrl-K.

h H               Display this help.
q :q Q :Q ZZ      Exit.
---------------------------------------------------------------------------
                  MOVING

e ^E j ^N CR      * Forward one line (or N lines).
y ^Y k ^K ^P      * Backward one line (or N lines).
f ^F ^V SPACE     * Forward one window (or N lines).
b ^B ESC-v        * Backward one window (or N lines).
z                 * Forward one window (and set window to N).
w                 * Backward one window (and set window to N).
ESC-SPACE         * Forward one window, but don't stop at end-of-file.
d ^D              * Forward one half-window (and set half-window to N).
u ^U              * Backward one half-window (and set half-window to N).
ESC-) RightArrow  * Left one half screen width (or N positions).

If you need to find the number of every line, use the -N option as shown below –

$ less -N /var/log/dpkg.log

The sample output should be like this –

1 2016-12-02 11:30:45 startup archives unpack
2 2016-12-02 11:30:45 install python-ptyprocess:all <none> 0.5-1
3 2016-12-02 11:30:45 status half-installed python-ptyprocess:all 0.5-1
4 2016-12-02 11:30:45 status unpacked python-ptyprocess:all 0.5-1
5 2016-12-02 11:30:45 status unpacked python-ptyprocess:all 0.5-1
6 2016-12-02 11:30:46 install python-pexpect:all <none> 4.0.1-1
7 2016-12-02 11:30:46 status half-installed python-pexpect:all 4.0.1-1
8 2016-12-02 11:30:46 status unpacked python-pexpect:all 4.0.1-1
9 2016-12-02 11:30:46 status unpacked python-pexpect:all 4.0.1-1
10 2016-12-02 11:30:46 install python-simplegeneric:all <none> 0.8.1-1
11 2016-12-02 11:30:46 status half-installed python-simplegeneric:all 0.8.1 11 -1
12 2016-12-02 11:30:46 status unpacked python-simplegeneric:all 0.8.1-1
13 2016-12-02 11:30:46 status unpacked python-simplegeneric:all 0.8.1-1
14 2016-12-02 11:30:47 install ipython:all <none> 2.4.1-1
15 2016-12-02 11:30:47 status half-installed ipython:all 2.4.1-1
16 2016-12-02 11:30:47 status triggers-pending man-db:amd64 2.7.5-1
17 2016-12-02 11:30:47 status triggers-pending hicolor-icon-theme:all 0.15- 17 0ubuntu1
18 2016-12-02 11:30:47 status half-installed ipython:all 2.4.1-1
19 2016-12-02 11:30:47 status triggers-pending gnome-menus:amd64 3.13.3-6ub 19 untu3.1
20 2016-12-02 11:30:47 status triggers-pending desktop-file-utils:amd64 0.2

To exit from the less command use q key or CTRL+C key. To change this behavior and automatically exit file when reaching the end of file use the following command

After this article, you will be able to understand – How to Use ‘less’ and ‘more’ Commands with Examples in Linux, we will come up with more Linux based tricks and tips. Keep reading!

Updated on: 2020-01-17T09:35:54+05:30

117 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements