πŸ“„ more Command

File Viewing Pager - The Classic Unix File Reader

Overview

The more command is one of the original Unix file viewers (pagers), allowing you to read text files one screen at a time. While it has been largely superseded by the more feature-rich less command, more remains available on all Unix/Linux systems and is still useful for simple, forward-only viewing. Understanding more is important for working on minimal systems, legacy scripts, and understanding Unix history.

Syntax: more [OPTIONS] [FILE...]

The more command displays file contents one screenful at a time, pausing after each screen. Press Space to advance, Enter for one line, or 'q' to quit. Unlike less, more primarily moves forward through files and has more limited navigation capabilities.

Example 1

Basic File Viewing

$ more README.txt This is a sample file for demonstration. It contains multiple lines of text that will be displayed one screen at a time. Press Space to continue... # At the bottom of screen: --More--(45%) # Press Space to see next screen # Press Enter to advance one line # Press 'q' to quit # Press 'h' for help

What's Happening:

The most basic use of more displays a file one screen at a time. At the bottom, you'll see a prompt showing the percentage of the file displayed. Press Space to move forward by one screen, Enter to move forward by one line, or 'q' to quit. The percentage indicator helps you know how much of the file remains.

Note: If the file fits on one screen, more displays it all and exits immediately without pausing.
Example 2

Viewing Multiple Files

$ more file1.txt file2.txt file3.txt :::::::::::::: file1.txt :::::::::::::: Content of first file... --More--(Next file: file2.txt) # Press Space to continue to next file :::::::::::::: file2.txt :::::::::::::: Content of second file... --More--(Next file: file3.txt) # Skip to next file immediately: # Press 's' to skip current file # Press ':n' to go to next file # Press ':p' to go to previous file (if supported) $ more *.log # View all .log files sequentially

What's Happening:

More can display multiple files sequentially. It shows a separator with the filename between files. You can navigate between files using special commands: 's' to skip the current file, ':n' for next file, and ':p' for previous (if your version supports it). This is useful for reviewing multiple log files or documents in sequence.

Pro Tip: Use wildcards to view related files: more /var/log/syslog* to view all syslog files.
Example 3

Starting at Specific Line Number

# Start viewing from line 100: $ more +100 largefile.txt [File content starting from line 100] --More--(45%) # Start from line 50: $ more +50 /var/log/syslog Nov 7 10:15:30 hostname systemd[1]: Started Session... [continues from line 50] # Combine with multiple files: $ more +20 file1.txt +30 file2.txt # file1.txt starts at line 20 # file2.txt starts at line 30 # Skip first 100 lines: $ more +100 data.csv # Useful for skipping headers in large data files

What's Happening:

The +N option makes more start displaying from line N instead of the beginning. This is invaluable when you know what part of a file interests you or when you want to skip headers. For large files, this saves time by jumping directly to the relevant section.

Note: Line numbers start at 1. Using +1 is the same as not using the option at all.
Example 4

Searching Within a File

$ more /var/log/syslog # While viewing, press '/' to search /error # Finds next occurrence of "error" # Search for pattern: /failed # Jumps to next "failed" string # Continue search: # Press 'n' for next occurrence # Case-insensitive search (if supported): # Some versions support this through options # Search from start: $ more +/ERROR logfile.txt # Opens file and jumps to first "ERROR"

What's Happening:

While viewing a file, press '/' followed by a search term to find text within the file. More jumps to the next occurrence. Press 'n' to find subsequent matches. You can also use +/pattern when invoking more to start at the first match. This is useful for quickly locating specific errors or keywords in log files.

Limitation: Unlike less, more can only search forward, not backward. For more sophisticated searching, use less instead.
Example 5

Using more with Pipes and Command Output

# View long command output: $ ls -laR /usr/local | more # Paginate recursive directory listing # View process list: $ ps aux | more USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 168820 13996 ? Ss Nov06 0:03 /sbin/init [more lines...] --More-- # View system logs: $ dmesg | more [ 0.000000] Linux version 5.15.0... --More-- # Filter and view: $ grep ERROR /var/log/app.log | more # View command help: $ gcc --help | more $ man bash | col -b | more # Convert man page to text and view # Pipeline with multiple commands: $ cat *.txt | sort | uniq | more

What's Happening:

More is frequently used with pipes to paginate command output. This is essential when commands produce more output than fits on one screen. Common uses include viewing long directory listings, process lists, logs, and help text. Piping to more prevents output from scrolling off the screen, giving you time to read it.

Best Practice: Pipe long outputs to more (or less) to make them readable. This is especially important in scripts where users need to review output.
Example 6

Controlling Screen Size and Line Count

# Specify number of lines per screen: $ more -10 file.txt # Shows 10 lines at a time (instead of full screen) # Useful for very tall terminals: $ more -50 longfile.txt # 50 lines per screen # Combine with starting line: $ more +100 -20 data.txt # Start at line 100, show 20 lines per screen # Set via environment: $ export LINES=30 $ more file.txt # Uses 30 lines # Ignore terminal size, use specified: $ more -15 /etc/passwd root:x:0:0:root:/root:/bin/bash [14 more lines] --More--

What's Happening:

The -N option (where N is a number) specifies how many lines more should display per screen. This overrides the terminal height. This is useful for creating consistent output in scripts, working with unusual terminal sizes, or when you want to see less at a time for careful reading. The LINES environment variable also affects this.

Note: If not specified, more auto-detects terminal height. Use -N for explicit control.
Example 7

Displaying Control Characters and Binary Files

# View file with control characters: $ more -v file_with_special_chars.txt # Control characters shown as ^X notation # Without -v (default behavior may vary): $ more binary_file.dat # May show garbled text or warning # Squeeze multiple blank lines: $ more -s textfile.txt # Multiple consecutive blank lines become one # View with both options: $ more -sv /var/log/debug.log # Show control chars, squeeze blanks # Example with actual control characters: $ echo -e "Line1\nLine2\n\n\n\nLine3" | more -s Line1 Line2 Line3 # Multiple blank lines squeezed to one

What's Happening:

The -v option displays control characters in a readable format (^X notation). The -s option squeezes multiple consecutive blank lines into a single blank line, making files with excessive spacing more readable. These options are useful when examining files that may contain special characters or when you want to reduce visual clutter from repeated blank lines.

Warning: Don't use more on binary files! Use hexdump, xxd, or strings instead. Binary data can confuse your terminal.
Example 8

Interactive Commands While Viewing

# While viewing with more, you can use: # Navigation: Space - Forward one screen Enter/↓ - Forward one line d - Forward half screen (11 lines by default) Ctrl+D - Forward half screen # Search: /pattern - Search forward for pattern n - Repeat last search # File commands (multiple files): :n - Go to next file :p - Go to previous file (if supported) :f - Display current file name and line number v - Start vi editor at current line (if available) # Other: h or ? - Display help q or Q - Quit = - Display current line number . - Repeat previous command # Example session: $ more largefile.txt [viewing...] = (shows line number) Currently at line 250 /error (search for "error") [jumps to error] n (find next error) h (show help) q (quit)

What's Happening:

While viewing files, more accepts interactive commands for navigation and searching. These commands don't require Enter (except for search patterns). The most important are Space (next screen), Enter (next line), '/' (search), and 'q' (quit). The '=' command shows your current position, useful in large files. The 'h' command displays all available commands.

Essential more Commands

Example 9

Using more in Scripts and Automation

#!/bin/bash # report-viewer.sh - Script to view reports with more REPORT_DIR="/var/reports" # Function to view report view_report() { local report=$1 if [ ! -f "$report" ]; then echo "Error: Report not found: $report" return 1 fi # Get file size size=$(stat -f%z "$report" 2>/dev/null || stat -c%s "$report") # If small file, just cat it if [ "$size" -lt 1000 ]; then cat "$report" else # Use more for larger files more "$report" fi } # Main menu while true; do echo "=== Report Viewer ===" echo "Available reports:" ls -1 "$REPORT_DIR" echo "" read -p "Enter report name (or 'quit'): " choice if [ "$choice" = "quit" ]; then break fi view_report "$REPORT_DIR/$choice" echo "" done # Another example: Viewing command output conditionally output_lines=$(command_that_produces_output | wc -l) if [ "$output_lines" -gt 50 ]; then command_that_produces_output | more else command_that_produces_output fi # Log viewer with auto-paging: #!/bin/bash # view-log.sh LOG_FILE=${1:-/var/log/syslog} TERM_HEIGHT=$(tput lines) FILE_LINES=$(wc -l < "$LOG_FILE") if [ "$FILE_LINES" -gt "$TERM_HEIGHT" ]; then echo "Log file has $FILE_LINES lines, using more..." more "$LOG_FILE" else cat "$LOG_FILE" fi

What's Happening:

These scripts demonstrate practical uses of more in automation. The first creates an interactive report viewer that uses more for large files. The second conditionally pipes output to more only when it's long enough to need pagination. The third auto-detects if a log file needs pagination. These patterns are useful in admin scripts, menu systems, and user interfaces.

Best Practice: Check file/output size before using more. For small content, direct output is faster. For large content, pagination improves readability.
Example 10

more vs less: When to Use Which

# Scenario 1: Minimal system (no less available) $ more /etc/passwd # more is present on ALL Unix/Linux systems # Scenario 2: Simple forward-only viewing $ ps aux | more # more is sufficient, less is overkill # Scenario 3: Viewing man pages $ man ls | more # Works, but less is better # Scenario 4: Quick file check $ more README # Quick and simple # When to use less instead: $ less /var/log/syslog # Better for: # - Backward navigation (b key) # - Better search (both directions) # - Line numbering (less -N) # - Multiple file navigation # - Viewing while file is being written (less +F) # - Color support # - More features in general # POSIX compatibility: $ more config.txt # more is POSIX standard, less is not # Emergency/rescue situations: $ more /root/recovery-notes.txt # more is often available when less isn't # Legacy scripts: $ old-script.sh | more # Scripts written before less was common

What's Happening:

This example highlights when to use more versus less. Use more when: you're on a minimal system, you need POSIX compatibility, you're only reading forward, you want simplicity, or you're maintaining legacy scripts. Use less when: you need backward navigation, better search capabilities, more features, or you're doing extensive file navigation. Most modern users prefer less, but more remains relevant for specific situations.

Remember: "less is more" (and more!)β€”the less command was created as an improved version of more. But more is universally available and perfectly adequate for simple tasks.

more vs less Feature Comparison

Feature more less
Forward navigation βœ“ Yes βœ“ Yes
Backward navigation βœ— No (limited) βœ“ Yes (full)
Forward search βœ“ Yes βœ“ Yes
Backward search βœ— No βœ“ Yes
Loads entire file βœ“ Yes βœ— No (streams)
Follow mode (tail -f style) βœ— No βœ“ Yes (less +F)
Line numbering βœ— No βœ“ Yes (less -N)
POSIX standard βœ“ Yes βœ— No
Available everywhere βœ“ Yes βœ— Usually (not always)
Memory efficient Lower Higher
Feature richness Basic Extensive
Man page default No Yes (usually)

Best Practices & Tips

πŸ’‘ When to Use more

πŸ“ Common Usage Patterns

⚠️ Limitations and Caveats

Quick Reference: more Options and Commands

Option/Command Description Example
+N Start at line N more +50 file.txt
+/pattern Start at first match of pattern more +/ERROR log.txt
-N Set screen size to N lines more -20 file.txt
-s Squeeze multiple blank lines more -s document.txt
-v Display control characters more -v special.txt
Space Forward one screen Press while viewing
Enter Forward one line Press while viewing
d Forward half screen Press while viewing
/pattern Search forward Type while viewing
n Repeat search Press while viewing
q Quit Press while viewing
h Help Press while viewing