
more Command in Linux
The more command in Linux is a simple yet powerful utility for viewing the contents of text files one screen at a time. It is particularly useful for reading large files that do not fit entirely on the screen. The more command is a versatile and powerful utility for viewing the contents of text files one screen at a time.
Table of Contents
Here is a comprehensive guide to the options available with the more command −
Understanding the more Command
The more command is used to display the contents of a file one screen at a time. It allows you to scroll through the file using various keyboard commands. It provides several options for customizing its behavior and can be used in combination with other commands to view various types of output.
Syntax of more Command
The basic syntax for using more is as follows −
more [options] file
Examples of more Command in Linux
Let's go through a few practical examples of how to use the more command in Linux −
Basic Usage of more
To view the contents of a file using more, simply specify the file name as an argument.
more example.txt

This command displays the contents of example.txt one screen at a time. You can press the spacebar to move to the next screen and the q key to quit.
Navigating with more
The more command provides several keyboard commands for navigating through the file −
- Spacebar − Move to the next screen.
- Enter − Move to the next line.
- b − Move back one screen.
- q − Quit the more command.
- /pattern − Search for a pattern.
- n − Move to the next occurrence of the search pattern.
- h − Display help.
Viewing Multiple Files
You can use more to view multiple files by specifying multiple file names as arguments.
more file1.txt file2.txt file3.txt
This command displays the contents of file1.txt, file2.txt, and file3.txt one after the other.
Using more with Piping
The more command can be used with piping to view the output of other commands one screen at a time.
ls -l | more

This command displays the output of the ls -l command one screen at a time.
Using more with Redirection
You can use more with redirection to view the contents of a file that is generated by another command.
cat example.txt | more

This command displays the contents of example.txt one screen at a time using more.
Using more with Options
The more command provides several options for customizing its behaviour. Some of the commonly used options are −
- -d − Display a message at the bottom of each screen.
- -c − Clear the screen before displaying the next page.
- -s − Squeeze multiple blank lines into a single blank line.
- -u − Suppress underlining.
more -d example.txt

This command displays the contents of example.txt with a message at the bottom of each screen.
Searching for more
You can search for a pattern within the file using the /pattern command.
more example.txt

Press /pattern and then Enter to search for the pattern within the file. Use the n key to move to the next occurrence of the pattern.
Using More with Environment Variables
The behaviour of more can be customized using environment variables. The MORE environment variable can be set to specify default options for the more command.
export MORE="-d -s" more example.txt

This command sets the MORE environment variable to display a message at the bottom of each screen and squeeze multiple blank lines into a single blank line.
Using More with Aliases
You can create an alias for more command with specific options to simplify its usage.
alias more='more -d -s' more example.txt

This command creates an alias for the more command with the -d and -s options.
Using more with Line Numbers
You can display line numbers using the nl command in combination with more.
nl example.txt | more

This command displays the contents of example.txt with line numbers, one screen at a time.
Using More with Colored Output
You can use the more command with coloured output by combining it with the grep command.
grep --color=always 'pattern' example.txt | more

This command highlights the pattern in example.txt with coloured output and displays it one screen at a time.
Using more with Large Files
The more command is particularly useful for viewing large files that do not fit entirely on the screen.
more largefile.txt

This command displays the contents of largefile.txt one screen at a time.
Using more with Log Files
You can use the more command to view log files that are continuously updated.
tail -f example.txt | more

This command displays the contents of logfile.txt one screen at a time and updates the display as new lines are added to the file.
Using more with Directories
You can use the more command to view the contents of directories by combining it with the ls command.
ls -l | more

This command displays the contents of the current directory one screen at a time.
Using more with Network Commands
You can use the more command to view the output of network commands such as netstat and ifconfig.
netstat -an | more

This command displays the output of the netstat -an command one screen at a time.
Using more with System Commands
You can use the more command to view the output of system commands such as dmesg and ps.
ps| more

This command displays the output of the dmesg command one screen at a time.
Using more Text Processing Commands
You can use the more command to view the output of text processing commands such as grep, awk, and sed.
grep /pattern example.txt | more

This command displays the output of the grep 'pattern' example.txt command one screen at a time.
Conclusion
By understanding and using the various options and commands available in more, you can effectively manage and view large files and command outputs on a Linux system.