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.
- Any Linux system
- Basic command line knowledge
- A good smile to learn
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.
Basic Syntax of more command:
more [options] filename
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:
Enter Keyto scroll down line by line.
Space barto navigate to next page.
bkey to go back one page.
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 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
-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.
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 bank line
If the file has multiple blank lines use
-s option to squeeze multiple blank lines into one bank 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.
Linux more command options
Some of the commonly used more command options:
|Allow to Press 'Space bar' to continue, 'q' to quit, Press 'h' for instructions, instead of sound when an illegal key is pressed|
|Long lines are not wrapped, kept as it is|
|clear the whole screen and then can view the text|
|Display by overlapping same area|
|Squeeze multiple blank lines|
|View specified number of lines in the window|
|Integer number from where the text to display|
|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.
|If you forgot commands use help to get a summary|
|Display next k lines of text|
|Scroll k lines|
|Skip forward k lines|
|skip backward k screenful of text|
|Go to kth next file|
|Go to kth previous file|
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.