Normally short text files are viewed using cat command. When it comes to large files cat command shows the last section, and you have to scroll up to read other sections. There is a better way to view files using Linux more command.
In this tutorial, we learn about Linux more command, and how to use it.
What is more command in Linux
Linux more command is used to display text files from the command line. This command is mostly used to display large files. More command helps to view files one screen at a time. It does not support backward scrolling (except for going back one page).
Basic Syntax of more command:
more [options] filename
The following table lists the options for more command:
Options
Description
-d
Allow to Press 'Space bar' to continue, 'q' to quit, Press 'h' for instructions, instead of sound when an illegal key is pressed
-f
Long lines are not wrapped, kept as it is
-p
clear the whole screen and then can view the text
-c
Display by overlapping same area
-s
Squeeze multiple blank lines
-u
Ignore underlines
-n
Search the string in each file before starting to display it
+n
Integer number from where the text to display
+/string
Search string in each file before starting to display it
Linux more also supports interactive commands those are based on vi. The k in the description means those commands may be preceded by a decimal number.
Interactive commands
Description
h
If you forgot commands use help to get a summary
<space>
Display next k lines of text
d
Scroll k lines
s
Skip forward k lines
b
skip backward k screenful of text
:n
Go to kth next file
:p
Go to kth previous file
How to Use More command
More command is usually used without any options. Type more followed by the filename to view the first page within the available screen size. More command is especially useful for forward navigation.
The bottom percentage shows the % of the file that more command has read.
Use the following commands to scroll the page:
Press Enter Key to scroll down line by line.
Press Space bar to navigate to next page.
Press b key to go back one page.
Press q key to quit more and return to the command line.
You can also use more command with other commands using the pipe. For example ls -l | more here more commands read the output of ls -l command.
The more command in Unix/Linux does not have a built-in option to directly go to the end of the file. With more, the navigation is primarily done by pressing Spacebar to go forward one page and b to go back one page, and it does not provide a way to skip directly to the end of a file.
The less command performs the same functionality of more command but has extensive enhancements. Mainly less command good at forward and backward navigation.
Linux more command Examples
Here let's check Linux more command capabilities with some examples.
Better user navigation using -d option
The -d option it allows to continue by pressing the Space bar and q to exit from reading. You can see a prompt at the bottom of each page for the same.
Example:
more -d /etc/ssh/ssh_config
Display First Specified Number of Lines of a file
To display a specified number of lines in a window, type:
more -5 /etc/ssh/ssh_config
Display Text After Specified number of Lines
Use +num option to display text after a specified number of lines of the file.
more +5 /etc/ssh/ssh_config
More will open the file named /etc/ssh/ssh_config at line number 5.
Squeeze multiple blank line
If the file has multiple blank lines use -s option to squeeze multiple blank lines into one blank line.
more -s /path/to/filename
Search a string
Use the option +/string to search for the string pattern in the text document.
more +/Proxy /etc/ssh/ssh_config
This search for the pattern 'Proxy' in the file named /etc/ssh/ssh_config. Remember the string search is case sensitive.
Conclusion
In this tutorial, we learned about Linux more command with examples. We have gone through some useful more command options which help to view text files. For more information check more manual page or type man more from the command line.
If this resource helped you, let us know your care by a Thanks Tweet.
Did you find this article helpful?
We are glad you liked the article. Share with your friends.
Comments