The more
command in Linux is a pager utility used to view the content of a file one screen at a time, allowing you to scroll through the content. It is especially useful when dealing with long files that don’t fit on a single screen.
How more
works:
- When you run
more
on a file, it displays the file’s content, pausing after each screenful of text. - You can navigate through the file using various keyboard shortcuts.
Basic Syntax:
more [options] [file_name]
Example 1: Viewing a text file
more example.txt
This will display the content of example.txt
one screen at a time. Press the Space
key to move to the next screen, or press Enter
to move down one line at a time.
Navigation Commands (while in more
):
- Space: Move to the next screen of content.
- Enter: Move one line down.
- b: Move one screen back (previous screen).
- /pattern: Search for a pattern within the file (e.g.,
/error
to find the word “error”). - n: Move to the next occurrence of the search pattern.
- q: Quit and exit
more
.
Example 2: Using more
with a pipe
You can also use more
with other commands using a pipe (|
), allowing you to view output from commands that produce a lot of data.
For example, to view the contents of a directory listing:
ls -l | more
This shows the output of the ls -l
command (long listing of files) one screen at a time.
Example 3: View large log files
In system administration, log files can be huge. You can view them with more
like this:
more /var/log/syslog
This will display the system log file one screen at a time, making it easier to read through long logs.
Example 4: View a compressed file with zmore
more
can also be used to view compressed files. For compressed .gz
files, you can use zmore
:
zmore file.gz
This works the same way as more
but with compressed files.
Conclusion:
more
is a simple yet powerful command for reading long files or command outputs in a paginated format. It’s great for navigating through large files interactively and can be combined with other commands for effective file exploration.