More Command in Linux

Learn via video courses
Topics Covered

Overview

When working in a Linux environment, it's essential to have a good understanding of the command-line interface and the various commands available. One such command is the more command, which is used to view text files one page at a time.

The More command in Linux is primarily used for viewing text files on Linux systems and is especially useful when dealing with large files. In this article, we will explore the more command in Linux, their syntax, options, and how to use them.

Introduction

The More command in Linux is a command-line utility that allows users to view text files one page at a time. The more command is often used when dealing with large files that cannot be viewed in their entirety on a single screen. It is a simple, yet powerful tool included in most Linux distributions.

The More command in Linux was developed as a replacement for the older cat command, which displayed text files in their entirety on a single screen. The more command was designed to be more user-friendly by displaying one page of text at a time and allowing users to navigate through the file using various commands.

Syntax of More Command in Linux

The basic syntax of the more command is as follows:

more command execute in terminal

The more command can be used with or without options. If a file is not specified, more will read from standard input.

Options of More Command in Linux

The more command in Linux has several options that can be used to customize their behaviour. These options are specified on the command line after the more command and can be combined in any order.

Some of the most commonly used options are:

OptionDescription
-n or --line-numbersThis option displays the line numbers at the beginning of each line.
-p or --percentThis option displays the percentage of the file that has been viewed.
-s or --squeeze-blankThis option removes empty lines from the output.
-c or --no-colorThis option disables color highlighting of the output.
-u or --underlineThis option underlines the output
-f or --forceThis option forces more command to display the file, even if it is small enough to fit on one screen.

How to Use More Command in Linux

To use the more command in Linux command, open a terminal window and type more command followed by the name of the file you want to view. For example, to view a file named "example.txt", type the following command:

more command execution in terminal

By default, more commands in Linux will display the file one page at a time. You can navigate through the file using various commands:

  • To move forward one page, press the spacebar or the "f" key.
  • To move backward one page, press the "b" key.
  • To move forward one line, press the "Enter" key.
  • To quit more commands, press the "q" key.

In addition to these basic commands, more commands have several other commands that can be used to navigate through the file or modify its behavior. Some of the most commonly used commands are:

-d

The -d option in the more command is used to specify the number of lines that should be displayed on each screenful of text. It allows you to control how much text is displayed at a time and can be useful for reading through long files.

By default, more will display one screenful of text at a time, which is typical 24 lines on most systems. However, you can use the -d option followed by a number to specify a different number of lines per screen.

For example, to display, you would use the following command:

executed d command in the terminal

/pattern

The /pattern option in the more command is used to search for a specific pattern or keyword within the file being viewed.

When you use the /pattern option with the more command, it will search for the next occurrence of the specified pattern in the file. Once found, it will display the page containing the pattern and wait for you to press the Enter key to continue to the next page.

Here's an example of how to use the /pattern option with the more command:

This command will display the contents of the syslog file, which contains system messages and error messages. If you want to search for a specific error message, you can use the /pattern option like this:

In this example, the more command will search for the next occurrence of the word "error" in the syslog file and display the page containing the word. You can then press the Enter key to continue to the next page.

You can also use regular expressions with the /pattern option to search for more complex patterns. For example, to search for all lines that start with the word "error", you can use the following command:

In this example, the caret (^) character is used to indicate that the pattern should match at the beginning of the line.

command executed with pattern in the terminal

-n

One of the options that can be used with the more command is the -n option. This option is used to specify the number of lines to be displayed on each page.

By default, more displays one page of text at a time, with each page containing 24 lines. However, if you want to view more or fewer lines on each page, you can use the -n option followed by the number of lines you want to view per page.

Here's an example of how to use the -n option to view five lines per page:

In this example, more command is used to view the contents of the myfile.txt file with five lines per page. You can change the number "5" to any number of lines that you prefer.

The -n option is useful when you are viewing a file with a large number of lines, and you want to view more content on each page to reduce the number of pages you need to navigate through. Conversely, if you are working with a file that has very short lines, you may want to reduce the number of lines per page to make it easier to read.

It's worth noting that the -n option only affects the number of lines displayed on each page, not the total number of pages in the file. If you want to jump to a specific line number in the file, you can use the +n option instead.

displaying n command executed in terminal

-h

This option displays a help screen with a list of available commands and their functions.

To use the "-h" option in more commands, simply type the following command:

This will display a help screen with the list of available commands and their corresponding functions. The help screen can be navigated by scrolling up and down using the arrow keys or by using the "Spacebar" to scroll down one page at a time.

The "-h" option is useful for new users who are not familiar with the various commands and options available in the more command. It can also be used as a quick reference for more experienced users who need a reminder of a specific command or function.

displaying the help command in terminal

-f

This option enables the continuous display of the contents of a file.

When the "-f" option is enabled, the file is displayed continuously, and new data is added to the display as it is written to the file. This option is particularly useful when monitoring log files or real-time data streams.

To use the "-f" option in more commands, simply type the following command:

This will display the file "filename.txt" with the continuous display enabled. The display can be paused at any time by pressing the "Spacebar", and resumed by pressing any other key.

The "-f" option is useful for monitoring the output of continuously running processes, such as log files, system monitoring tools, or network traffic. With the continuous display enabled, the user can easily keep track of changes and updates in real time, without the need to manually refresh the display.

displaying f command executed in terminal

+linenum

The +linenum option in the more command allows you to start displaying a file from a specific line number.

For example, if you want to start viewing a file from line number 20, you can use the command:

This will display the file starting from line number 20, and you can use the spacebar to navigate through the file.

If you want to start viewing a file from the beginning but skip the first 10 lines, you can use:

This will start displaying the file from line 11.

The +linenum option can be useful when you want to quickly jump to a specific section of a large file.

displaying line number option in terminal

These were the few most used options for more commands in Linux.

Conclusion

  • The More command in Linux is a command-line utility that allows users to view text files one page at a time.
  • The basic syntax of the more command in Linux command is "more [options] [file]".
  • The more command in Linux command has several options that can be used to customize its behavior, such as line numbers, percentage of the file viewed, squeeze-blank, no-color, underline, and force.
  • To use the more command in Linux command, open a terminal window and type more command in Linux followed by the name of the file you want to view.
  • More commands in Linux have several commands that can be used to navigate through the file or modify its behavior, such as search for a pattern, repeat a search, display a help screen, display the current file name and line number, and run a shell command without exiting more command in Linux.
  • More command in Linux is a simple yet powerful tool that is included in most Linux distributions and is especially useful when dealing with large files.
  • In summary, the more command in Linux command is a useful tool for viewing text files on Linux systems. It is a simple yet powerful utility that can be customized to meet the needs of the user. By understanding the basic syntax and available options and commands, users can make the most of this powerful tool and improve their productivity in the Linux environment.

MCQs

1. Which Command Is Used to View Text Files One Page at A Time in Linux?

  • i) cat command
  • ii) ls command
  • iii) more command
  • iv) cp command

Answer: iii) more command

2. What is the Basic Syntax of The More Command in Linux?

  • i) more [options] [file_name]
  • ii) more [file_name] [options]
  • iii) more [options]
  • iv) more [file_name]

Answer: i) more [options] [file_name]

3. Which Option is Used to Disable Color Highlighting of The Output in The More Command?

  • i) -n or --line-numbers
  • ii) -p or --percent
  • iii) -s or --squeeze-blank
  • iv) -c or --no-color

Answer: iv) -c or --no-color