What is the difference between "more" and "less" commands?

12,356

Solution 1

more is the oldest, less is an improvement and most is an improvement on that.

Short comparison:

  • more: forward navigation and limited backward navigation.
  • less: both forward and backward navigation and also has search options. You can go to the beginning and the end of a file instantly. Plus you can switch to an editor (like open the file in vi or vim). It is noticeably quicker than editor for when the file is large.
  • most: has all the features of more and less but you can also open multiple files, close 1 file at a time when you have multiple files open, allows locking and scrolling of the open windows and allows for splitting of open windows.

All 3 use the h to let you view the keybindings for the command.

Solution 2

The Joke

There is an old joke consisting of three words: “less is more”. (This is the “pun” referred to by guillermo chamorro's second comment to the question.) Perhaps one reason why people like the joke so much is that the statement can be understood in three different ways, and so there isn't any clarity about which way is meant. Yet, all three of the ways are accurate, at least on some operating systems. (Point #2 might not apply to Ubuntu, and I do understand that this is an Ubuntu-focused site. However, Ubuntu derives from Debian wish has strong history of ideas being taken from, and shared with, the rest of Unix and Unix-ish systems. So, understanding what other operating systems do isn't a bad thing.)
  1. There is a variable named LESS_IS_MORE
  2. As an indisputable fact of less's nature (on some operating systems)
  3. As a simple English statement

To clarify these:

  1. There is a variable named LESS_IS_MORE.
    • The less command supports a shell/environment variable named LESS_IS_MORE. The less command acts quite a bit like the older more command by default, but if the less command sees this variable is set to a value of 1 (the number one), then the less command will offer fewer features in an attempt to be increase just how compatible it is with the older pager command that is named more.
    • This is not Ubuntu-specific, and is supported by less on all platforms. This is mentioned by less(1) (less's "man page"), section titled “Compatibility with more.
  2. As an indisputable fact of less's nature (on some operating systems)
    • The less command supports a behavior which many programs utilize in Unix-like environments, which is the behavior of checking which filename it was run as. If the command line which ran the less program started with a filename of more, then what the program named less will do is to act with increased compatibility with the older more command, similar to what it would so if the LESS_IS_MORE command is run.
    • Some operating systems have actually relied upon this functionality, and not bothered to include a separate program named more. Well, to be clear, there is an available command named more (which is highly recommended for compatibility with scripts and some quite-common user behavior), but the less and more commands are both “hard links” to the same stream of bits of executable code. So, the executable code which the operating system runs when running the command named less actually is the same executable code which the operating system runs when running the command named more. (This isn't even just a case of an identical copy of the code being run. Literally, the same bits get loaded by reading from literally the same exact location of the data-storage device, so it is quite literally the same code that gets used.) So, the statement that less is more refers to a literal (factual, non-opinionated, provable) truth, as these are literally the exact same program since both of these programs are literally using the exact same executable code. (However, the program may differ in behavior based on which command was used to run the program.)
    • If someone says “less is more, literally.” then the person is probably trying to clarify that the less command and the more command are sharing the same executable bits. This can be done as a “hard link” (implemented using ln) most efficiently, but could also be implemented using a “symbolic link” (implemented using ln -s), or by having a duplicate copy of the executable file's bits (which can be easily implemented using cp).
  3. As a simple English statement
    • This is an opinionated statement (which very many people agree with), stating that the less command has a greater number of nice features, and so the less command is a better experience than what is offered by the older, more traditional pager command (which happens to be named more). Since the experience of using the command named less is a significantly nicer experience, people feel that it is appropriate to describe that nicer experience as being “MORE!”.

Throughout this answer, I did strive to make all references to the command be noticeably marked. However, the best way to experience the joke is verbally, because that adds to some of the ambiguity. Verbally, saying

  • “LESS_IS_MORE”
  • or “less is more
  • or “less is MORE!”

might all be pronounced in exactly the same way, so if voice tone doesn't clearly indicate any particular emphasis on any specific words, then simply hearing the three words gives no real indication of precisely which accurate statement(s), if any, was intended to be referenced to a greater extent than the other statement(s).

All humor aside, this may also be used as a bit of a way to measure someone's familiarity with this command Unix program. Many people don't read the “man page” for every single command before they use the command (especially when learning how to effectively use some of the most basic commands on the first Unix platform they use), so many people end up learning about the LESS_IS_MORE variable when this joke is fully explained. So, verbally saying this joke can be a way to check how much acknowledgement or confusion the recipient seems to have.

(If the person looks a bit perplexed, that could be an indication that this can be a good time will be taken to help educate the person about the multiple aspects of this statement. Based on the first point or two, they end up knowing a bit more about the behavior of a common command. And if they remember the joke, then they can remember the last point, which helps them to remember about the existence of the less command which many people are happier with, and remember which command typically provides a nicer experience on many platforms.)

DOS compatibility

There is one aspect to the “more” command that is worth mentioning, which might make it seem nicer (in the opinions of at least some people) than the “less” command.

Very, very many Unix(-ish) systems come with both a command named more and a command named less, built-in, installed as part of the operating systems. (The command named most, which further builds upon the less command, is mentioned by one of the other answers, but is pre-installed on far fewer systems. So, installing the program needs to be done first.) However, the more command may also be pre-installed on a larger number of computers, including computers that are not typically thought of as being designed primarily around Unix compatibility.

In MS-DOS and similar/compatible platforms, including modern Microsoft Windows, the following will work precisely like it does with Unix:

  • more < filename.txt

You can also pipe into more. A typical way of demonstrating this is to show a command that reveals the contents of a text file. In Unix, that is often done using cat. MS-DOS does not have a cat command, but instead uses type. (Unix has a separate type command that does something quite different.) So:

  • Unix: cat file.txt | more
  • DOS: type file.txt | more

(Remember, when I mention DOS, that also applies to modern Microsoft Windows, not to mention other systems like OS/2. So, these DOS references are as relevant to the modern world today as what Microsoft Windows is.)

As a more modern example, the following works on modern Microsoft Windows systems, and also on many Unix systems:

  • netstat -na | more

With modern versions, you can also specify one or more filenames on the command line. If you do, the first file will be shown, and then the next file will be shown.

  • more fileone.txt filetwo.txt

While the less command is available for MS-DOS, Microsoft Windows, and other operating systems, the program is often not pre-bundled. So, the less command is not available unless some effort is made to install the system. If you step foot into a computer lab that you have not been to before, chances are quite good that the command named more might be readily available, while the command named less might typically only be available on Unix platforms. For some people, this may be an advantage to the command named more which is significant enough for them to prefer to get used to running that command.

Misc

I don't try to provide the entire answer here, because doing so would just be redundant with the other answers. Instead, I decided to just include information that I wasn't seeing elsewhere. So this answer is designed to be supplemental to some other answers. I hope you enjoyed the information presented here, but definitely check out the other answers. Both of the pre-existing answers (posted before this one) also provided additional information.

Solution 3

less lets you navigate upwards as well as downwards.

That's the most important difference, but there are many others. less provides numerous features beyond those in more. You can press H in less and it will show you its abbreviated help, explaining how to use its various interactive features.

Most common are Spacebar or Page Down to go down one screenful of text and B and Page Up to go back up one screenful of text. All four arrow keys work (though the up and down arrows are the ones most often useful).

less also differs from more in some ways that pertain to performance, resource usage, and accommodating unusual terminals. As man less says:

Less is a program similar to more (1), but it has many more features. Less does not have to read the entire input file before starting, so with large input files it starts up faster than text editors like vi (1). Less uses termcap (or terminfo on some systems), so it can run on a variety of terminals. There is even limited support for hardcopy terminals. (On a hardcopy terminal, lines which should be printed at the top of the screen are prefixed with a caret.)

Commands are based on both more and vi. Commands may be preceded by a decimal number, called N in the descriptions below. The number is used by some commands, as indicated.

I've been comparing less to a traditional implementation of more. In Ubuntu, more is such an implementation. However, if you invoke less but as the name more--as would happen if you made a symlink or hardlink to less called more and ran that--then it behaves differently, resembling more aesthetically but allowing you to move both upward and downward in documents.

Share:
12,356
BlueSkies
Author by

BlueSkies

Updated on September 18, 2022

Comments

  • BlueSkies
    BlueSkies almost 2 years

    What is the difference between the two commands below?

    more file-name
    less file-name
    
  • fiatux
    fiatux over 4 years
    Also handy with less: G to jump to bottom of file then F to follow new content (like tail -f). Ctrl-C to stop following and you can navigate the file once again.
  • BlueSkies
    BlueSkies over 4 years
    The abbreviated help brought up by pressing H is also seachable
  • Pablo Bianchi
    Pablo Bianchi over 4 years
    Yet another great alternative: bat, available on official repos since Ubuntu Eoan 19.10 or Debian unstable sid.
  • ash
    ash over 4 years
    @PabloA bat is not a pager, it relies on less for that.
  • Pablo Bianchi
    Pablo Bianchi over 4 years
    @Josh you're right, more precisely bat is a cat alternative but the overall experience is like a less with steroids.
  • user253751
    user253751 over 4 years
    @JörgWMittag It has to go with Linux (the complete operating system, not the kernel) because Linux has these commands. Otherwise it's like someone said "I hate Windows because of drive letters." and you said "I fail to see what drive letters have to do with Windows. Drive letters are from CP/M." - makes no sense, does it?
  • ski
    ski over 4 years
    @user253751: There are Linux operating systems that don't use GNU and thus don't have less. There are Linux operating systems that aren't Unix-compatible and thus don't have more. No Linux operating system I ever used had most installed by default. Some even didn't have it at all. Conversely, all non-Linux Unices have more. There are GNU operating systems that have less but don't use Linux. There are operating systems that have most but don't use Linux. For example, I use macOS, which has nothing to do with Linux, and I have all three.
  • user253751
    user253751 over 4 years
    It's not GNU/Linux, anyway. It's Apache/Mozilla/KDE/Wayland/OpenJDK/Eclipse/.../GNU/Linux.
  • ski
    ski over 4 years
    @user253751: I did not know that, and I have never heard anybody use it this way. Anyway, it doesn't really make a difference, since most is not part of GNU, so the argument that most has nothing to do with Linux still holds even if, for some strange reason, you choose to re-define "Linux" to mean "GNU/Linux". I have always taken "Linux" to mean "Linux", "GNU" to mean "GNU" and "GNU/Linux" to mean "GNU/Linux". I think it would be very confusing to have both "Linux" and "GNU/Linux" mean "GNU/Linux" and have "Linux" not mean "Linux".
  • user253751
    user253751 over 4 years
    @JörgWMittag Well I think it's confusing to have "GNU/Linux" not mean "GNU/Linux".
  • Jesús Franco
    Jesús Franco over 4 years
    This should be one of the better answers I've ever read on this SE😊
  • Pogrindis
    Pogrindis over 4 years
    most is new to me! Nice