Could less show the viewed proportion of text file?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Over a Mysterious Island Looping
--
Chapters
00:00 Could Less Show The Viewed Proportion Of Text File?
00:22 Answer 1 Score 24
00:30 Accepted Answer Score 32
00:52 Answer 3 Score 6
01:02 Answer 4 Score 7
02:04 Thank you
--
Full question
https://superuser.com/questions/64972/co...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #editing
#avk47
ACCEPTED ANSWER
Score 32
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)
ANSWER 2
Score 24
Do you mean like with the -M
switch?
ANSWER 3
Score 7
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.
ANSWER 4
Score 6
less -M +Gg
for not very big files it's OK, because +G
(G
command) go till the end of file