Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Syntax
3.
Options
4.
Examples
4.1.
Example 1: Basic Usage
4.2.
Example 2: Using the -d Option
4.3.
Example 3: Adjusting Line Count per Screen
4.4.
Example 4: Skipping to a Specific Line
4.5.
Example 5: Combining Options
4.6.
Example 6 : Clear Screen Between Pages
4.7.
Example 7 : Ignoring Form Feed
4.8.
Example 8 : Starting From a Specific Line
4.9.
Example 9: Interactive Navigation:
5.
Frequently Asked Questions
5.1.
Can I search for text within the 'more' command?
5.2.
How do I exit the 'more' command?
5.3.
Is it possible to view multiple files with 'more'?
6.
Conclusion
Last Updated: Mar 27, 2024
Easy

More Command in Linux

Author Sinki Kumari
0 upvote
Create a resume that lands you SDE interviews at MAANG
Speaker
Anubhav Sinha
SDE-2 @
12 Jun, 2024 @ 01:30 PM

Introduction

Linux, a powerhouse in the world of operating systems, offers a plethora of commands to make navigating and managing files a breeze. Among these, the "more" command stands out as a fundamental tool for displaying text files in a terminal. Ideal for beginners and seasoned users alike, mastering the "more" command can significantly enhance your command-line efficiency. 

More Command in Linux

This article aims to equip you with a solid understanding of the "more" command, covering its syntax, various options, and practical examples to get you started.

Syntax

The syntax of the "more" command is straightforward, making it accessible for users of all experience levels. At its core, the command follows a simple structure:

more [options] file_name


To use "more," you simply type more followed by the name of the file you wish to view. For example, more example.txt will display the contents of "example.txt" in your terminal window. If the file extends beyond the current viewable area of the terminal, "more" will pause at the end of the screen, displaying a prompt that indicates the percentage of the document viewed so far.

The simplicity of the "more" command's syntax is one of its key advantages. It doesn't require memorizing complex flags or options to get started, making it an excellent tool for beginners. However, for those looking to customize their viewing experience, "more" does offer a range of options to modify its behavior, which we will explore in the next section.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Options

The "more" command, while simple in its basic form, offers several options to enhance and customize the user experience. These options allow for more flexibility and control over how content is displayed in the terminal. Here are some of the most commonly used options with "more":

Option Description
-d Displays the message [Press space to continue, 'q' to quit.] at the end of each page, guiding users on how to navigate.
-I Ignores the form feed character (ASCII 0x0C) as a page delimiter, useful for files using this character for other purposes.
-f Counts logical lines rather than screen lines, aiding in viewing lines longer than the screen width.
-c Clears the screen and displays new content at the top of the window for each new page, instead of scrolling.
-n<number> Sets the number of lines to display at a time, allowing for customized page lengths. For example, -n 10 displays 10 lines per screen.
+<number> Starts displaying the file from the specified line number, enabling users to jump directly to a specific part of the document. For instance, +50 starts from the 50th line.

Examples

Let's put the "more" command into action with some practical examples. These will illustrate how to use "more" effectively in different scenarios, utilizing the options we've discussed.

Example 1: Basic Usage

To view the contents of a file named tutorial.txt, you would use the following command:

more tutorial.txt


This command displays the contents of tutorial.txt, pausing each time the displayed content fills the screen. You can press the space bar to continue to the next page.

Example 2: Using the -d Option

If you want more explicit instructions on how to navigate through the text, you can use the -d option:

more -d tutorial.txt


This command will display [Press space to continue, 'q' to quit.] at the end of each page, guiding users unfamiliar with the command.

Example 3: Adjusting Line Count per Screen

For files with content that requires closer inspection, you might want to reduce the number of lines displayed at once. Using the -n option allows you to do just that:

more -n 10 tutorial.txt


This command displays 10 lines of tutorial.txt at a time, offering a more detailed view at each pause.

Example 4: Skipping to a Specific Line

If you're interested in viewing the content starting from a specific line number, you can use the +<number> option. For example, to start viewing from line 50:

more +50 tutorial.txt


This command opens tutorial.txt starting from the 50th line, which is useful for jumping directly to relevant sections of a file.

Example 5: Combining Options

You can combine multiple options to customize your viewing experience further:

more -d -n 10 +50 tutorial.txt


This command will start displaying tutorial.txt from line 50, show 10 lines at a time, and provide navigation prompts.

Example 6 : Clear Screen Between Pages

Using the -c option clears the terminal screen before displaying the next page of the file. This can help reduce clutter and make each page of content feel fresh:

more -c report.txt


This approach can be particularly beneficial when presenting data or sections that are best viewed independently.

Example 7 : Ignoring Form Feed

In files where form feed characters are not intended to mark page breaks, the -l option ensures they're treated as regular characters:

 

more -l data.txt


This can be crucial for files containing special formatting or encoded data.

Example 8 : Starting From a Specific Line

To jump directly to a certain part of a file, the +<number> syntax is invaluable. For instance, to start viewing from line 100 in chapter3.txt:

more +100 chapter3.txt


This can save time and effort when you need to focus on a specific section of a file.

Example 9: Interactive Navigation:

While viewing a file, remember that you can press the space bar to move to the next page or 'b' to go back a page. This interactive element makes "more" user-friendly and adaptable to your pace.

Frequently Asked Questions

Can I search for text within the 'more' command?

Yes, while viewing a file with 'more', you can search for text by typing / followed by the search term and pressing Enter. 'more' will then jump to the next occurrence of the term.

How do I exit the 'more' command?

To exit while using 'more', simply press q. This will immediately return you to the command prompt.

Is it possible to view multiple files with 'more'?

Absolutely! You can view multiple files sequentially by listing them after the 'more' command, like more file1.txt file2.txt. 'more' will start with the first file and then proceed to the next after you reach the end.

Conclusion

In conclusion, the "more" command in Linux is a simple yet powerful tool for viewing text files in a terminal. Its easy-to-understand syntax and helpful options make it accessible for users of all skill levels, from beginners to advanced users. Whether you're scrolling through lengthy log files, examining configuration files, or just reading through documentation, "more" provides a convenient way to manage your viewing experience. By incorporating the various options like -d for navigation instructions, -l to ignore form feed characters, or -n to specify the number of lines per screen, you can tailor the command to suit your specific needs. Remember, mastering commands like "more" can significantly enhance your efficiency and effectiveness in navigating the Linux command line.

You can refer to our guided paths on the Coding Ninjas. You can check our course to learn more about DSADBMSCompetitive ProgrammingPythonJavaJavaScript, etc. 

Also, check out some of the Guided Paths on topics such as Data Structure and AlgorithmsCompetitive ProgrammingOperating SystemsComputer Networks, DBMSSystem Design, etc., as well as some Contests, Test Series, and Interview Experiences curated by top Industry Experts.

Live masterclass