Command: more (with examples)

Command: more (with examples)

The more command is a useful tool for displaying paginated output from stdin or a file. It allows users to view the contents of a file or the output of a command one page at a time, making it easier to read and navigate through large amounts of information.

Display paginated output from stdin

echo test | more

Motivation: Sometimes, you may have a command that generates a large amount of output, and you want to view it in a controlled manner rather than having it all display at once. In such cases, you can use more to display the output one page at a time, allowing you to read through it comfortably.

Explanation: The echo command is used to output the string “test” to stdout. By using the pipe operator |, we pass this output as the stdin to the more command. more then displays the output one page at a time.

Example Output:

test
-- More --

Display paginated output from one or more files

more path\to\file

Motivation: In situations where you want to view the contents of a file without overwhelming your terminal with all the content at once, you can use the more command to display the file contents in a paginated manner.

Explanation: The command more followed by the file path allows you to view the contents of the specified file one page at a time. more will display the first page of the file and wait for user input to continue viewing subsequent pages.

Example Output:

This is the first line of the file.
This is the second line of the file.
This is the third line of the file.
-- More --

Convert tabs to the specified number of spaces

more path\to\file /t4

Motivation: In some cases, files may contain tab characters used for indentation. If you prefer to view these tabs as spaces, you can use the more command with the /t argument followed by the number of spaces per tab.

Explanation: The /t argument followed by a number specifies the number of spaces to replace each tab character with. Using more in conjunction with this argument will display the file with the specified tab width.

Example Output:

This is the first line of the file.
This is the second line of the file, with an indentation of four spaces.
This is the third line of the file.
-- More --

Clear the screen before displaying the page

more path\to\file /c

Motivation: If your terminal screen is cluttered with previous commands or output, you may want to clear it before displaying the paginated output from more. This allows for a cleaner and more focused reading experience.

Explanation: The /c argument tells more to clear the screen before displaying each page of output. This ensures that only the current page is visible and previous contents are not cluttering the view.

Example Output:

(first page of output after clearing the screen)
-- More --

Display the output starting at line 5

more path\to\file +5

Motivation: Sometimes, you may only be interested in viewing the output starting from a specific line within a file. Instead of scrolling through unnecessary content, you can use the more command with the + argument to specify the starting line.

Explanation: The + argument followed by a line number tells more to start displaying the output from that particular line in the file. This allows you to directly view the desired portion of the file.

Example Output:

This is the fifth line of the file.
This is the sixth line of the file.
This is the seventh line of the file.
-- More --

Enable extended interactive mode

more path\to\file /e

Motivation: The extended interactive mode provides additional options and functionality to enhance the user experience while using the more command. This mode enables features such as scrolling, searching, and navigation within the output.

Explanation: The /e argument activates the extended interactive mode of more. By enabling this mode, you gain access to advanced features like scrolling through the output, searching for specific words or phrases, and navigating to different sections of the file.

Example Output: (No visible change in the output for this specific use case.)

Display full usage information

more /?

Motivation: For a complete understanding of the more command and all its available options, it is helpful to view the full usage information. This provides details on various arguments, switches, and their descriptions.

Explanation: When the more command is used with the /? argument, it displays the full usage information and available options. This includes explanations of all the command’s arguments, switches, and their respective functionalities.

Example Output:

MORE [/E [/C] [/P] [/S] [/Tn] [+n]] [[drive:][path]filename[ ...]]

/E   Enable extended features
/C   Clear screen before displaying page
/P   Expand FormFeed characters
/S   Squeeze multiple blank lines into a single line
/Tn  Expand tabs to n spaces (default is 8)
+n   Start at line n
(...)

Related Posts

How to use the command 'dolt status' (with examples)

How to use the command 'dolt status' (with examples)

The dolt status command is used to display the status of the database session.

Read More
Using the git repack Command (with examples)

Using the git repack Command (with examples)

Pack unpacked objects in the current directory To pack unpacked objects in the current directory, you can use the following command:

Read More
How to use the command fusermount (with examples)

How to use the command fusermount (with examples)

The fusermount command is used to mount and unmount FUSE (Filesystem in Userspace) filesystems.

Read More