A Tale of β€œMore” and β€œLess” Commands in Linux

Linux TLDR
Last Updated:
Reading time: 5 minutes

Linux users often use β€œmore” and β€œless” commands interchangeably to read large files without understanding their differences, as their definitions are also identical in the manual.

So, what’s their difference, and when should you use them? All of this doubt will be cleared in this article, including how to effectively use them with practical examples.

But first, let’s start with their definition:

The more command is used to read large files by displaying one page at a time and scrolling up and down through pages; you can even pipe it with other commands like cat.

The less command can be considered an extended version that inherits all the more command features and delivers additional features and functionality that the more command lacks.

Like easy navigation and search options, it does not load the complete file but instead accesses it page by page, which optimizes the loading speed while reading large files.

Showing the differences between both of these commands might not make sense because the β€œless” command is way more advanced compared to the β€œmore” command, but if you’re interested in learning more, read our complete article and also check this.

Tutorial Details

DescriptionMore & Less Commands
Difficulty LevelLow
Root or Sudo PrivilegesNo
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Prerequisitesmore, less
Internet RequiredNo

So, this article will be divided into two sections: first, we will start with the β€œmore” command and then the β€œless” command.

If you are a beginner and just ended up here to learn about a tool to read a large file, I recommend that you skip the more command section and directly jump to the less command section.

Part 1: The β€œMore” Command

The more commands take two arguments: one is the option, and the other is the file name (or complete path pointing towards the file).

$ more [OPTION] [FILE]

The complete options can be checked using the β€œmore --help” command. As this command is rarely used today, we will just focus on the most relevant examples.

But don’t forget to check the following key maps that will come into use while viewing the file:

EnterMove forward one line.
Space bar | Up arrowMove forward one page.
B | Down arrowMove backward one page.
/patternSearch forward for matching patterns.
=Print the current line number.
vOpen the specified file in the β€œ/usr/bin/vi” editor or program.
!Execute the commands in the sub-shell.
.Repeat the previously executed command.
hOpen the help section.
qQuit the screen.

Reading a File

You can directly specify the file as an argument to more command or you can pipe it with other commands, as shown.

$ more article.txt


$ cat article.txt | more


more command

Directly Open the File at a Specific Line

Open the file from a specific line instead of from the beginning by using the β€œ+[N]” format and replacing the β€œN” with the line number.

$ more +50 article.txt


Opening the file from a specific line

Printing the First Few Lines

Identical to the previous command, you can specify the number of lines that you just want to print in β€œ-[N]” format; replace β€œN” with the number of lines.

$ more -5 article.txt


Printing the first five lines from the file

Displaying the Help Menu at the Bottom of the File

The β€œ-d” flag will guide you at the bottom of the file, like β€œ[Press space to continue, β€˜q’ to quit.]” and displays β€œ[Press β€˜h’ for instructions.]” when the wrong key is pressed.

$ more -d article.txt


Displaying help instead of ringing the bell

Reading the Logical rather than Screen Lines

The β€œ-f” flag will count the logical lines that are not wrapped by the screen width, showing you the actual lines.

$ more -f article.txt


Reading the logical rather than screen lines

Squeezing the Multiple Blank Lines into One

The β€œ-s” flag will replace the sequence of multiple blank lines with one single line, making output cleaner.

$ more -s article.txt


Removing the extra blank lines from the file

Omitting the Bold and Underlines

The β€œ-u” flag will suppress the string if it contains bold or underlines.

$ more -u article.txt


Omitting the bold and underlines

The rest of the things are not that important, and you might rarely use them, so I did not cover them. So, leaving the more command examples here, let’s move on to the less command examples.

Part 2: The β€œLess” Command

The less command also accepts two arguments: one is the option, and the other is the filename or path pointing towards a file.

$ less [OPTION] [FILE]

The following are known options that will come into use while using this command:

-EAutomatically quit the file once it reaches the end, behaving like more command.
-fForce the non-regular files to open.
-FIf the content size fits the screen size, then close the interactive screen.
-gOnly highlight the strings that match the last search.
-GDon’t highlight any string matches from the last search.
-iIgnore the case in searches that do not contain uppercase.
-IIgnore case in all searches.
-nSuppress the line number.
-pStart the file with the first occurrence of the pattern.
-sSqueeze the multiple blank lines into one.

Also, check the following key maps that come into use while viewing the file:

Down arrow, Enter, e, or jMove one line forward.
Up arrow, y, or kMove one line backward.
Space bar or fMove one page forward.
bMove one page backward.
/patternSearch forward for matching patterns.
?patternSearch backward for matching patterns.
nRepeat the previous search.
NRepeat previous searches in a backward direction.
gGo to the first line in the file.
NgGo to the nth line in the file.
GGo to the last line in the file.
pGo to the beginning of the file.
NpGo to line N percent into the file.
vEdit the current file with $VISUAL or $EDITOR.
!Execute the commands in the sub-shell.
hDisplay help.
qQuit the interactive screen.

Reading a File

Specify the filename or path pointing towards a file as an argument to the less command; it can also be used with other commands through piping.

$ less article.txt


$ cat article.txt | less


less command

Multiple files can be viewed by separating each one of them with a space, and you can easily swim between all the files using the β€œ:n” (move forward) or β€œ:p” (move backward) commands.

Displaying All the Matched Occurrences in the File

Use the β€œ-p” flag with a string to highlight all matching occurrences in the referenced file.

$ less -p "less" article.txt


Highlighting all the matched occurrence in the file

Displaying the Exact Matched Occurrences in the File

In the previous command, if the specified string comes in between another word or is relative to another word, like β€œthe” for β€œtheyβ€œ, β€œthemβ€œ, β€œtheirβ€œ, etc. are relative strings, they all get highlighted, and strings with different case like β€œThe” with a capital β€œT” did not get highlighted.

This all can be easily resolved by using the β€œ-i” flag, which will ignore all cases, and specifying a space at the end of the string after specifying it inside double quotes to find an exact match.

$ less -i -p "the " article.txt


Searching for exact match in the file

Printing the Line Number

The β€œ-N” flag will print the line number at the beginning of each line, which can be very useful while configuring the configuration file.

$ less -N article.txt


Showing output along with line numbers

End the Interactive Screen if the Content of the File Fits with Screen

If the content properly fits on the screen without cropping, the β€œ-F” flag will automatically close the interactive screen (or quit the less command).

$ less -F shortfile.txt


Automatically close the file if the content fits with screen size

Unclear the Screen After Closing the File

By default, when you leave the file using the β€œq” key, the content of the file is cleared from the screen; this can be easily prevented using the β€œ-X” flag; it will leave content on the screen.

$ less -X article.txt


Leaving the content on screen

Monitor File Changes

Like the watch and tail commands, less also provides you with the option to monitor file changes in real time using the β€œ+F” flag.

For example, I’ve misconfigured my nginx configuration file, so when the server tries to start, the error will be saved to the β€œ/var/log/nginx/error.log” file, which will be monitored using the less command.

$ sudo less +F /var/log/nginx/error.log


Monitor file changes in less command

Alternatively, you can also use the β€œShift+f” shortcut key to enter watching mode, unlike flag.

So, the article ends here.

However, if any useful examples that should be added to this article are left, then please inform us in the comment section.


Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.