111

I'm struggling to figure out a way to do this...I'm using less to view a large (~1GB) file. I want to jump to line "$n" in the file - preferably without having to wait for lines 1-($n-1) to scroll by in my terminal.

I would do this in vim using something like this:

localhost:~# vim myfile +$n

Is there an equivalent command line option? If not, is there a way to do this once the file is open in less?

1
  • 4
    A question that bothered me again and again, when i didn't have the time to search for an answer. Typing 'h' might have helped, for it displays the "SUMMARY OF LESS COMMANDS"...
    – lajuette
    Commented Mar 14, 2011 at 16:29

1 Answer 1

171

If the file is open you can type:

  • 100g to go to the 100th line.

  • 50p to go to 50% into the file.

  • 100P to go to the line containing 100th byte.

You can use these from terminal by adding + in front of them:

less +100g bigfile.txt
4
  • 11
    And don't forget, you can type $ to go to the last line.
    – rob
    Commented Feb 24, 2010 at 20:21
  • Note that without any suffix it goes to the Nth line less +100 bigfile.txt
    – CharlesB
    Commented Apr 23, 2021 at 8:53
  • can also use 50% to jump to 50%. More typing but easier to remember, and that also works in vim
    – wisbucky
    Commented Feb 15, 2022 at 4:32
  • Thanks, I knew about less +G ... to go to the end of the file. but not the less +nnng .... I have always resorted to using less, but felt concerned sometimes in case I made inadvertent alterations (especially as occasionally these might be production files!) Commented Oct 21, 2023 at 17:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .