more Command in Linux with Examples

This tutorial explains Linux “more” command, options and its usage with examples.

“more” command is used to file perusal filter for crt viewing. This post describes “more” command used in Linux along with usage examples and/or output.

Usage:
more [options] filename

more command is used to display text in the terminal screen. It allows only backward movement.
Programs of this sort are called pagers. “more” is a very basic pager, originally allowing only forward navigation through a file, though newer implementations do allow for limited backward movement.

Here’s the listing of example usage of “more” command:
We will be using sample.txt file as an example.

sanfoundry-> cat sample.txt 
Line 1
Line 2 
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

1. To see the contents of the file(more file_path):

advertisement
advertisement
sanfoundry-> more sample.txt 
Line 1
Line 2 
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

2. To Clear screen before displaying(more -c file_path):

sanfoundry-> more -c sample.txt
 
 
 
Line 1
Line 2 
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

The output is shown on the new screen.

3. To Specify how many lines are printed in the screen for a given file(more -n file_path):

sanfoundry-> more -4 sample.txt 
Line 1
Line 2 
Line 3
Line 4
--More--(39%)

Here first n numbers of lines with the % amount of the lines are printed. Hit CTRL+c to get the shell prompt back.

4. To Start up the file from the given number(more +n file_path):

sanfoundry-> more +4 sample.txt 
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

5. To Display error messages rather than ringing the terminal bell if an unrecognized command is used(more -d ..):
This is helpful for inexperienced users.:

advertisement
sanfoundry-> more -d sample 
sample: No such file or directory

6. Doesn’t display extra blank lines(more -s file_path):

sanfoundry-> cat sam.txt 
Line 1
 
Line 2
 
 
 
 
Line 3 
Line 4 
sanfoundry-> more -s sam.txt 
Line 1
 
Line 2
 
Line 3 
Line 4

Here we can see that there are 4 blank lines between Line 2 and Line 3. But with the addition of “-s” option the blank lines are reduced from 4 to 1.

advertisement

7. To Displays text two lines before the first time text appears(more +/pattern file_path):

sanfoundry-> cat sam.txt 
Hi 
HI
I
am 
good
boy
sanfoundry-> more +/good sam.txt 
 
...skipping
I
am 
good
boy

Here as you can see that to display the output just before two lines, the further lines are skipped. This is very useful in debugging the code.

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.