How can I get file information in 'less' like with 'man'?

1

When I view a file in Linux with the 'less' command, I often only get a ":" prompt in the bottom left corner. There's no clue about how long the file will be, or at which location I am currently. When reading manpages with 'man', there's a file title and line number in that corner. And once I hit the end of the file, there's even a percentage shown. I've learned about 'less -m' but it's not that powerful. So what does 'man' differently from 'less'? They appear to be the same viewing programme, except for that file information difference.

(Using Ubuntu 10.4 LTS)

ygoe

Posted 2010-07-31T21:51:59.017

Reputation: 1 597

Answers

3

strace man

reveals that it just calls pager.

man pager

reveals that pager is actually less. And indeed

$ ls -al /usr/bin/pager
lrwxrwxrwx 1 root root 23 2009-08-18 17:30 /usr/bin/pager -> /etc/alternatives/pager
lrwxrwxrwx 1 root root 13 2009-08-18 17:19 /etc/alternatives/pager -> /usr/bin/less

so less has some presets which are invoked when called by the name pager.

Actually strace also reveals these environment variables:

"LESSCHARSET=utf-8",
"LESS=-ix8RmPm Manual page less(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e 
(END):?pB %pB\\%..$PM Manual page less(1) ?ltline %lt?L/%L.:byte %bB?s/%s..?e
(END):?pB %pB\\%..$",

So that's it!

mvds

Posted 2010-07-31T21:51:59.017

Reputation:

Okay, I now found that there's a LESS environment variable and that you can specify "prompts" in less. But the manpage is so very complicated to read in that section that I probably do that later if at all. Or does anybody know a practical solution for that? Using the very environment variable from above doesn't change a thing for me. – ygoe – 2010-08-09T17:30:39.773

3

less -M will show current line information in the status area.

Joseph Spiros

Posted 2010-07-31T21:51:59.017

Reputation: 131

1

less is designed to work with a stream (a pipe) which length is normally not known. Man is always working on file, so it could always provide this information.

Moisei

Posted 2010-07-31T21:51:59.017

Reputation: 131

less can operate on files just fine. By default it shows the filename initially, and there are options that will make it show it constantly. – Matthew Flaschen – 2010-07-31T22:05:49.177

1

Have you tried looking at man less or typing (I think) H in less to see the gazillion options? I'd look it up for you but I'm not on a Linux machine at the moment.

Carl Smotricz

Posted 2010-07-31T21:51:59.017

Reputation: 629

1

Ctrl-G will give you some file stats at the bottom of the page.

Noel M

Posted 2010-07-31T21:51:59.017

Reputation: 175

0

That information comes from the LESS environment variable, which man populates. You can find the value in the man page for man. I recommend considering the most pager instead. You can do this by installing most and changing the PAGER environment variable. It has useful features like colorization, and will show the filename at all time by default.

Matthew Flaschen

Posted 2010-07-31T21:51:59.017

Reputation: 2 370

0

On Ubuntu I tried Colorful man suggested on commandlinefu and have been satisfied.

kalyanji

Posted 2010-07-31T21:51:59.017

Reputation: 1

0

add alias less='less -RM +Gg' to your .bashrc, adjust it if you are using fish-shell.

CodyChan

Posted 2010-07-31T21:51:59.017

Reputation: 469