Search Command in Less: See Target Line in Context

  • Thread starter Thread starter nvn
  • Start date Start date
  • Tags Tags
    Search
Click For Summary
SUMMARY

The discussion focuses on modifying the behavior of the Linux 'less' command to improve the visibility of search results. Users expressed the need to prevent the target search string from appearing at the top of the session window. The solution is to utilize the 'less -jN' option, where 'N' specifies the number of lines to keep above the search result, allowing for better context visibility. This adjustment enhances the user experience when navigating through files with the 'less' command.

PREREQUISITES
  • Familiarity with Linux command line operations
  • Understanding of the 'less' command and its basic functionalities
  • Knowledge of command-line options and syntax
  • Basic understanding of file navigation in Linux
NEXT STEPS
  • Explore the 'less' command man page for additional options and features
  • Learn about other command-line tools for file viewing, such as 'more' and 'cat'
  • Research advanced text searching techniques in Linux using 'grep'
  • Investigate customizing terminal settings for improved usability
USEFUL FOR

This discussion is beneficial for Linux users, system administrators, and developers who frequently work with text files and seek to enhance their command-line navigation efficiency.

nvn
Science Advisor
Homework Helper
Messages
2,128
Reaction score
32
When perusing a file using the linux less command, and you use the less search command inside less, I would like to know how to make less not display the line containing the target search string as the very top line of the session window (very poor design). I want the target line to always be at least the fourth line down from the top of the window (or lower), so I can see the found string in context, showing a few lines before (and after) the target line. Any help would be appreciated.
 
Technology news on Phys.org
Problem solved. The problem is solved by using the less -jn option, explained on the less man page.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 26 ·
Replies
26
Views
6K
  • · Replies 5 ·
Replies
5
Views
4K