Operations 9 min read

Master Linux Log Viewing: More, Less, Cat, Head & Grep Commands Explained

This guide walks you through essential Linux commands—more, less, cat, head, and grep—detailing their parameters, key actions, and practical examples for efficiently filtering and navigating large log files during development and operations.

Java Interview Crash Guide
Java Interview Crash Guide
Java Interview Crash Guide
Master Linux Log Viewing: More, Less, Cat, Head & Grep Commands Explained

During development, you often need to locate errors in large online logs such as log4j output, requiring Linux filtering tools like less, more, cat, head and grep.

more Command

-num: display starting from the specified line number.

+num: start showing from line num .

+/pattern: search for pattern in each file, then display from two lines after the match.

Space: show the next screen.

Enter: show the next n lines (default 1).

H: display help.

B: show the previous n lines (default 1).

Q: quit.

=: output the current line number.

f: output the file name and current line number.

more Command Examples

Example 1: Show content from the third line onward more +3 linux.log Example 2: Find the first occurrence of "day3" and display from two lines before

more +/day3 linux.log
$ more +/day3 linux.log ...skip... 2018-04-day1 2018-04-day2 2018-04-day3

Example 3: Limit output to 5 lines per page

ll | more -5

less Command

Enter: move down one line.

y: move up one line.

Space: scroll down one screen.

b: scroll up one screen.

d: scroll down half a screen.

h: help.

u: scroll up half a screen.

w: start display from the line after the specified number.

g: go to the first line.

G: go to the last line.

p n%: jump to n % of the file.

/pattern: search for pattern .

v: invoke the vi editor.

q: quit.

!command: run a shell command, e.g., !ls .

less Common Options

-c: refresh the screen from the top.

-f: force open binary files without warnings.

-i: ignore case unless the pattern contains uppercase.

-I: ignore case unless the pattern contains lowercase.

-m: show the percentage of the file read.

-M: show percentage, line number, and total lines.

-N: display line numbers.

-p pattern: search for pattern , e.g., less -p MAIL /etc/profile .

-s: squeeze multiple blank lines into one.

-Q: suppress the terminal bell.

+num: start display from the specified line.

Typical usage: less -m -i -N linux.log (show line numbers, percentage, and case‑insensitive search).

cat Command

Used to view and concatenate files; suitable for small texts, not ideal for large logs.

-n or --number: number all output lines starting at 1.

-b or --number-nonblank: number only non‑blank lines.

-s or --squeeze-blank: replace multiple consecutive blank lines with a single blank line.

-A: show non‑printable characters, display $ at line ends.

-e: equivalent to -vE .

-t: equivalent to -vT .

cat Examples

cat m1

Display the contents of file m1. cat m1 m2 Show m2 after m1. cat m1 m2 > file Merge m1 and m2 into file.

head Command

-n<number>: show the first number lines.

-c<bytes>: show the first bytes characters.

-v: always display the file name.

-q: never display the file name.

Example: head -n 4 linux.log shows the first four lines of linux.log.

grep Command

Powerful text search tool using regular expressions.

grep Common Usages

grep -E 'at |Execption |exception |Caused by' log.log

Search for exception‑related lines in a log. grep match_pattern log.log Find lines containing match_pattern in a single file. grep "match_pattern" file_1 file_2 file_3 ... Search across multiple files. grep "match_pattern" file_name --color=auto Highlight matches. grep -C10 pattern filename Show ten lines of context before and after each match.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CATGreplesslogheadmore
Java Interview Crash Guide
Written by

Java Interview Crash Guide

Dedicated to sharing Java interview Q&A; follow and reply "java" to receive a free premium Java interview guide.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.