pattern Verified current stable Not installed? Documentation

Pattern / Backward Search String

Backward Search String

Command for executing backward string searches for quickly locating previous occurrences of specified strings in files.

$
Terminal
<?><pattern>

When To Use

During log review, when searching for the most recent error or event requires rapid backtracking.

Pro Tip

Use enhanced search patterns for better accuracy, and limit searches in extensive logs to avoid slowdowns.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
<?><pattern>

Anatomy of Output

Understanding the result

Found pattern: warning Detected String

String searched for is marked found.

Previous match line number: 50 Location

Shows where the prior instance was found.

Occurrences found: 5 Occurrence Summary

Total detections found before the current instance.

Power User Variants

Optimized versions

pattern -i <pattern>

Perform a case-insensitive search.

pattern -n <pattern>

Output line numbers for matches.

Unix Pipeline

Shell combinations

pattern -c <pattern>

Count rather than display matching lines.

pattern -r <regex>

Search using regex for complex criteria.

Troubleshooting

Common pitfalls

Error: No matches found

Solution: Ensure the pattern is correct and exists in the file.

Regex syntax error

Solution: Recheck regex for correct format.

Memory limit exceeded

Solution: Increase memory limits or optimize the search.

Command Breakdown

What each part is doing

<?><pattern>
Base Command
The executable that performs this operation. Here it runs Pattern before the shell applies any redirect operators.
<pattern>
pattern
The value supplied for pattern.

Alternative Approaches

Comparable commands in other tools

Alternative documentation tools for the same job.