Linux more Command: File Scrolling

LinuxLinuxBeginner
Practice Now

Introduction

This tutorial provides an overview of the more command in Linux, focusing on its functionality for displaying text files in a page-wise manner.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux/BasicFileOperationsGroup -.-> linux/more("`File Scrolling`") subgraph Lab Skills linux/more -.-> lab-214299{{"`Linux more Command: File Scrolling`"}} end

more Command

The more command is utilized for viewing the contents of text files interactively, allowing users to navigate through the content page by page.

Command Usage

Let's start with a basic example of using the more command. We have the file example.txt in the path /home/labex/project. Consider the following command and its output:

terminal

Input:

more /home/labex/project/example.txt

Output:

Line 1: This is a example text file.
Line 2: It contains multiple lines of text.
Line 3: You can use the 'more' command to view this file.
Line 4: Press the spacebar or enter to advance to the next page.
Line 5: Press 'q' to quit viewing the file.
2023-11-5 a
2023-11-5 b
2023-11-5 c
2023-11-5 d
2023-11-5 e
2023-11-5 f
2023-11-5 g
2023-11-5 h
2023-11-5 i
2023-11-5 j
2023-11-5 k
2023-11-5 l
2023-11-5 m
2023-11-5 n
2023-11-5 o
2023-11-5 p
2023-11-5 q
2023-11-5 r

In this example, the example.txt file is processed by more, and the output displays the content page by page, allowing users to navigate through the file.

Parameters and Usage Examples

The more command offers a variety of parameters to customize its behavior. We will introduce some of the most commonly used ones and provide usage examples in increasing order of complexity.

Option Parameter

more [OPTION]

  • +n: Start from nth line.
  • -n: Define the screen size as n lines.
  • +/pattern: Search for the pattern before each file is displayed, then start from the first two lines of the string.

When you use the more command, press = to output the current line number, press q to exit more, and press Space bar to scroll down one screen.

Example Usage

1. More Lines (+)

The more +n option with more starts displaying the file from line number n onward.

Input:

more +20 /home/labex/project/example.txt

Output:

## Displays the content of example.txt starting from line number 20
2023-11-5 o
2023-11-5 p
2023-11-5 q
2023-11-5 r

2. Less Lines (-)

The more -n option with more displays n lines per screen. It pauses after each screenful.

Input:

more -5 /home/labex/project/example.txt

Output:

## Displays the content of example.txt with 5 lines per screen
Line 1: This is a example text file.
Line 2: It contains multiple lines of text.
Line 3: You can use the 'more' command to view this file.
Line 4: Press the spacebar or enter to advance to the next page.
Line 5: Press 'q' to quit viewing the file.

The more +/pattern option with more starts displaying the file from the line containing the specified pattern.

Input:

more +/2023-11-5 /home/labex/project/example.txt

Output:

## Displays the content of example.txt starting from the line containing the pattern "2023-11-5"
Line 4: Press the spacebar or enter to advance to the next page.
Line 5: Press 'q' to quit viewing the file.
2023-11-5 a
2023-11-5 b
2023-11-5 c
2023-11-5 d
2023-11-5 e
2023-11-5 f
2023-11-5 g
2023-11-5 h
2023-11-5 i
2023-11-5 j
2023-11-5 k
2023-11-5 l
2023-11-5 m
2023-11-5 n
2023-11-5 o
2023-11-5 p
2023-11-5 q
2023-11-5 r

Summary

In this tutorial, we explored the more command, highlighting its role in interactively displaying text files. By introducing basic usage, common parameters, and example scenarios, users can leverage the more command for efficient navigation and examination of text file contents.

Other Linux Tutorials you may like