What is the difference between "more" and "less" commands?
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 ofmore
andless
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.
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.
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.)- There is a variable named LESS_IS_MORE
- As an indisputable fact of less's nature (on some operating systems)
- As a simple English statement
To clarify these:
- There is a variable named
LESS_IS_MORE
.- The
less
command supports a shell/environment variable namedLESS_IS_MORE
. Theless
command acts quite a bit like the oldermore
command by default, but if theless
command sees this variable is set to a value of 1 (the number one), then theless
command will offer fewer features in an attempt to be increase just how compatible it is with the older pager command that is namedmore
. - This is not Ubuntu-specific, and is supported by
less
on all platforms. This is mentioned byless
(1) (less
's "man page"), section titled “Compatibility withmore
”.
- The
- 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 theless
program started with a filename ofmore
, then what the program namedless
will do is to act with increased compatibility with the oldermore
command, similar to what it would so if theLESS_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 namedmore
(which is highly recommended for compatibility with scripts and some quite-common user behavior), but theless
andmore
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 namedless
actually is the same executable code which the operating system runs when running the command namedmore
. (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 thatless
ismore
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
ismore
, literally.” then the person is probably trying to clarify that theless
command and themore
command are sharing the same executable bits. This can be done as a “hard link” (implemented usingln
) most efficiently, but could also be implemented using a “symbolic link” (implemented usingln -s
), or by having a duplicate copy of the executable file's bits (which can be easily implemented usingcp
).
- The
- 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 theless
command is a better experience than what is offered by the older, more traditional pager command (which happens to be namedmore
). Since the experience of using the command namedless
is a significantly nicer experience, people feel that it is appropriate to describe that nicer experience as being “MORE!”.
- This is an opinionated statement (which very many people agree with), stating that the
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
ismore
” - 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.