More Command
The more command is a fundamental Unix/Linux utility
used to view the contents of text files one screen at a time. It's
particularly useful for large files where displaying the entire
content at once would be impractical.
How to Use the More Command
The basic syntax for the more command is:
more [options] [file ...]
Viewing Files Line by Line
To view a file named <file>, you would simply
type:
more <file>
Once the first screen of content is displayed, you can navigate using the following keys:
- Spacebar: Scroll down one full screen.
- Enter: Scroll down one line.
- 'q': Quit the
morecommand. - 'h': Display help information.
Starting from a Specific Line
A common and powerful feature of the more command is
its ability to start displaying a file from a specific line number.
This is achieved using the + option followed by the
line number.
For example, to show the file <file> beginning at
line number 5:
more +5 <file>
This is incredibly useful for quickly jumping to a particular section of a log file or configuration file without having to scroll through the entire preceding content.
Additional Options and Use Cases
While the +N option is frequently used,
more also supports other options for controlling its
behavior, such as displaying files piped from other commands. For
instance, you can pipe the output of the cat command to
more:
cat <file> | more
This is functionally similar to just using
more <file> but demonstrates its versatility in
shell scripting and command chaining.
Comparison with Less
It's worth noting that the less command is a more
advanced pager that offers similar functionality to
more but with additional features like backward
scrolling and more flexible navigation. However,
more remains a simple and effective tool for basic file
viewing.