This tutorial explains Linux “more” command, options and its usage with examples.
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):
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.:
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.
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.
- Check Linux Books
- Apply for Programming Internship
- Check Information Technology Books
- Practice Programming MCQs