How to Use the ‘more’ Command in Linux

Learn how to use 'more' in Linux to make large text files more manageable.

The more Linux command is a powerful tool that allows users to view text files in the terminal one screen at a time. It’s an essential command for anyone who frequently works with large text files. By breaking down the content into manageable chunks, the more command enhances readability and navigation, making it easier to analyze and understand the data within the file.

Similar to the more command, the less command offers additional flexibility and features, such as backward navigation. Both commands are commonly used for viewing log files, configuration files, and other text documents within the Linux environment. For those looking to combine commands for more complex tasks, the more command can be used alongside tools like grep to search for specific patterns within a file.

How to Use more

1. Viewing a File

Syntax: more [filename]

Explanation: Displays the content of a file one screen at a time.

Example: more myfile.txt

Output:

This is line 1
This is line 2
--More--(10%)

The output shows the first few lines of myfile.txt and indicates that 10% of the file has been displayed. Pressing the spacebar will show the next screen of content.

2. Viewing Multiple Files

Syntax: more file1 file2 ...

Explanation: Displays the contents of multiple files sequentially.

Example: more file1.txt file2.txt

Output:

Contents of file1.txt
--More--(file 1 of 2)

The output shows the contents of file1.txt and indicates that it’s the first of two files. You can navigate through the files using the same controls as viewing a single file.

3. Searching Within a File

Syntax: more [filename], then type /pattern to search.

Explanation: Allows searching for a specific pattern within the file.

Example: more myfile.txt, then type /line 3

Output:

This is line 3
--More--(20%)

After opening myfile.txt with more, typing /line 3 searches for the text line 3 and displays the corresponding line, indicating that 20% of the file has been displayed.

4. Viewing a File with Line Numbers

Syntax: more -n [filename]

Explanation: Displays the content of a file with line numbers.

Example: more -n myfile.txt

Output:

1 This is line 1
2 This is line 2
--More--(10%)

The output shows the first few lines of myfile.txt with line numbers, and indicates that 10% of the file has been displayed.

5. Viewing a File with a Specific Number of Lines per Screen

Syntax: more -num [filename]

Explanation: Displays the content of a file with a specific number of lines per screen.

Example: more -5 myfile.txt

Output:

This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
--More--(25%)

The output shows the first five lines of myfile.txt and indicates that 25% of the file has been displayed.

6. Piping Output to “more”

Syntax: [command] | more

Explanation: Pipes the output of another command through more to view it one screen at a time.

Example: ls -l | more

Output:

-rw-r--r-- 1 user user 1234 Jan 1 12:00 file1.txt
-rw-r--r-- 1 user user 5678 Jan 1 12:01 file2.txt
--More--

The output shows the long listing of files in the current directory, displaying them one screen at a time. The --More-- prompt indicates there is more content to view.

7. Viewing a File and Exiting on the First Match of a Pattern

Syntax: more +/pattern [filename]

Explanation: Opens the file and jumps directly to the first occurrence of the specified pattern.

Example: more +/line3 myfile.txt

Output:

This is line 3
This is line 4
--More--(20%)

The output shows the content starting from the first occurrence of line3 in myfile.txt, indicating that 20% of the file has been displayed.

More Linux commands:
Directory Operations rmdir · cd · pwd · exa · ls
File Operations cat · cp · dd · less · touch · ln · rename · more · head
File System Operations chown · mkfs · locate
Networking ping · curl · wget · iptables · mtr
Search and Text Processing find · grep · sed · whatis · ripgrep · fd · tldr
System Information and Management env · history · top · who · htop · glances · lsof
User and Session Management screen · su · sudo · open
WebsiteFacebookTwitterInstagramPinterestLinkedInGoogle+YoutubeRedditDribbbleBehanceGithubCodePenWhatsappEmail