Could less show the viewed proportion of text file?

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?

thanks.


Solution 1:

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)

Solution 2:

Do you mean like with the -M switch?

Solution 3:

less -M +Gg

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

Solution 4:

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.