Less -jn or –jump-target=n option specifies a line on the screen where the “target” line is to be positioned. The target line is the line specified by any command to search for a pattern, jump to a line number, jump to a file percentage or jump to a tag. The screen line may be specified by a number: the top line on the screen is 1, the next is 2, and so on. The number may be negative to specify a line relative to the bottom of the screen: the bottom line on the screen is -1, the second to the bottom is -2, and so on. Alternately, the screen line may be specified as a fraction of the height of the screen, starting with a decimal point: .5 is in the middle of the screen, .3 is three tenths down from the first line, and so on.
If the line is specified as a fraction, the actual line number is recalculated if the terminal window is resized, so that the target line remains at the specified fraction of the screen height. If any form of the -j option is used, repeated forward searches (invoked with “n” or “N”) begin at the line immediately after the target line, and repeated backward searches begin at the target line, unless changed by -a or -A. For example, if “-j4” is used, the target line is the fourth line on the screen, so forward searches begin at the fifth line on the screen. However nonrepeated searches (invoked with “/” or “?”) always begin at the start or end of the current screen respectively.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
## create a long file with 200 lines > myfile; i=1; while [ $i -le 200 ]; \ do echo "$i" >> myfile; ((i++)); done ## default less myfile ## in the interactive mode, type /9 ## target line is displayed on line no. 9 ## with respect to the screen ## less -jn or --jump-target=n option less -j20 myfile ## in the interactive mode, type /9 ## target line is desplayed on line no. 20 ## with respect to the screen rm myfile |