How To Use More Command.
In this guide, we look at the Linux more command and demonstrate how you can make the most out of it.
The cat command is a very handy tool when viewing short text files. However, when you have large files, it only gives you the last section of the file that constitutes the last few lines of the file. This compels you to scroll all the way up to start reading the file from the very beginning.
A better approach is to make use of the Linux more command. The command displays one section of the file at a time and allows you to comfortably scroll all the way to the end of the file.
The Linux more command takes the following syntax:
Linux more Command Without Any Options
In its basic form, the more command displays the first section of the file. By pressing the “ENTER” key, you can scroll line by line, all the way to the bottom of the file.
Here, we are displaying the /etc/ssh/sshd_config file using the more command:
To scroll line by line, just press “ENTER”.
To sift through the configuration file page by page, tap on the “SPACE BAR” key.
Linux more Command with the -d Option
With the -d command option, the more command prompts you to either proceed to view the file by pressing the “SPACE” key or simply exit by pressing the “Q” key on the keyboard.
Display First N Lines of a File
In the first two examples, the more command displays the first section of the file. To display the very first 10 lines, for example, run the command below:
This displays the first 10 lines of the file, whereupon, you can continue scrolling normally by pressing the “ENTER” key.
Squeeze Blank Lines in a File
Multiple blank lines in a file can often be a put-off. If you have a file with multiple blank lines, you can remove them on display by simply using the -s option, as shown below
Use more Command to Read the Output of Another Command
Additionally, you can pipe the output of the cat command to more command as provided below. This is akin to invoking more command without any command options.
Those are some of the most commonly used more command options. For more options, visit the man pages.
Viewing large files can be a challenge using the basic cat command or text editors such as nano or vim. The Linux more command allows you to comfortably go over the file line by line or page by page.