1

I'm taking an Intro to Linux class in college. Our teacher wants us to show a command that can be used for this question:

"Display the contents of a file with paging control that provides line-by-line navigation."

He said the only correct answer is "less". But can't less and more both operate in the same way? You can go line-by-line (Enter) or page-by-page (Space) with both correct?

Edit:

I guess I should have just asked if more and less (sorry I'm not sure how to format these words and images as other posters do) can operate relatively the same way in that they can both go through a file or directory line-by-line or page-by-page (screenful at a time). They either can or they can't I would assume.

From my experience, reading (I have a Linux+ book that also states they can both operate the same), and comments like Anthony's, it appears that they do both operate in that way.

4
  • 1
    Voting to close as opinion-based, since the answer will depend on what your teacher means by line-by-line navigation. Also there are potentially many more tools which can display a file and provide navigation. Jan 27, 2017 at 8:59
  • I asked him what he meant by line-by-line. He said to read the man page for more which states it only goes page by page. When I pointed out that it can also go line-by-line, he said he knows it sounds contradictory, but less is the correct answer.
    – exar
    Jan 27, 2017 at 9:01
  • @DmitryGrigoryev I think my answer shows how the POSIX specification is sufficiently unambiguous (as good standards should be). The opinion of one teacher carries far less weight than the careful deliberations of the Open Group standards committee(s). Jan 27, 2017 at 10:49
  • I should probably clarify my previous comment: @DmitryGrigoryev is correct that there are “potentially many more tools which can display a file and provide navigation” so it seems ridiculous that a teacher would insist there’s only one correct answer. My point is that we’re only answering exar’s question. We’re not trying to satisfy the teacher (or to argue semantics with them). What the teacher personally thinks is just background context for the question and isn’t relevant when answering the question. If exar uses information from answers to make their case, that’s his/her choice. Jan 27, 2017 at 16:08

4 Answers 4

4

I don’t think the teacher’s question is particularly useful for someone learning Unix – and their expected answer even less so. The less utility is widely used on modern Unix-like operating systems but it’s not actually mandated by POSIX. On the other hand, the more utility is specified by POSIX – and this specification includes line-by-line navigation.

POSIX describes more as a utility to “display files on a page-by-page basis” but its Extended description describes line-by-line navigation features, e.g., Scroll Forward One Line. For what it’s worth, any implementation of more that I’ve personally used only allowed pressing Enter to scroll forward one line at a time (so not fully POSIX compliant).

Note that on some systems, more can be symbolically linked to the less executable. In this case, less emulates the more command (as specified by POSIX). You might think you’re running more — but in reality, you’re running less (this emulation can also be achieved by setting the environment variable LESS_IS_MORE to 1). You can tell if you’re really running less in this compatibility mode by pressing -V, i.e., - followed by ShiftV while viewing a file. This prints the version number of less if running in less, e.g., less 481 while in (most implementations of) more, it will do nothing.

2
  • So if I do less -v it'll show me the version number and if I do more -v it won't do anything, and that shows that less isn't emulating more? Did I understand that correctly?
    – exar
    Jan 27, 2017 at 23:10
  • @exar I've edited my answer to clarify that point. Jan 28, 2017 at 15:24
1

More can go only forward, but with less you can also go backwards to the beginning of the file.

0

Less command just buffers the content, that you see in the terminal, to memory. But more command buffers all the content of the file to the memory and then shows the content. The only but really big difference between them. Less is more efficient :)

0

With more, you can navigate backwards: "line-by-line" with k or "page-by-page" with b.

0

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