As the title implies, when I am browsing text file,I would like to know the current viewed porportion of the whole text file.

I know that with -N option,we could turn on the line numbers,but how could I make less display the line number of the whole text file?



If you open a file with less then pressing Ctrl-g will display the current line number, total lines and percentage as well as shown below:

lines 51-100/185 byte 3228/5886 54% (press RETURN)

  • 1
    thanks.after revisiting the man page,manage to find it and get the other two equal command ':f' and '='.sorry for this. – Jichao Nov 3 '09 at 13:29

Do you mean like with the -M switch?

  • That's exactly what I want! – Jichao Nov 3 '09 at 13:31
  • Or -m if line-number is not necessary. – Franklin Yu Oct 25 '17 at 15:26

less -M +Gg

for not very big files it's OK, because +G (G command) go till the end of file

  • Great for $MANPAGER though! See man man. – Tom Hale Jan 13 '17 at 12:30

Just expanding a wee bit on the previous answers. Command line:

less -M +Gg

does the following:

-M Show current position within the file on the prompt +Gg Run commands G (go to the end of the file) and g (go back to the beginning of the file)

If less is reading from stdin, which happens when man is showing a man page, it doesn't know the total number of lines in the file in advance, so that it can properly calculate its position. Therefore, +Gg is necessary so that less can get the total number of lines, and thus calculate the current position as a percentage.

I found it useful to set these variables in ~/.bashrc:

export LESS+='-M'
export MANPAGER='less +Gg'

LESS will ensure that all invocations of less will show the current position on the prompt, and MANPAGER will ensure that less will be able to get the total number of lines in the man page, which less will then show on the prompt. It seemed to be more sensible not to include +Gg in LESS to prevent less from trying to go to the end of potentially large piped input. If that's necessary, one can always run the commands G and g manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.