This subchapter looks at less, more, and pg, a related family of UNIX (and Linux) commands.
less, more, and pg are utilities for reading a very large text file in small sections at a time.
pg is the name of the historical utility on BSD UNIX systems.
more is the name of the historical utility on System V UNIX systems.
pg and more are very similar and have almost the same functionality and are used in almost the exact same manner, except for whether you type pg or more.
less is a more modern version that has the capaibilites of more along with additional new capabilities.
Mac OS X has all three versions installed. It is common to find both more and less on Linux systems. The older versions are typically included so that old scripts written before the invention of less will still work.
The name less is a pun, from the expression less is more.
Try using less with your test file file01.txt.
You are going to try less first.
$ less file01.txt
If that doesnt work, you are going to try more next.
$ more file01.txt
If that doesnt work, you are going to try pg last.
$ pg file01.txt
One of the three will work. You can try the others to see if they are available on your system, but for the exercise, use the first one that works.
$ less file01.txt This is a line of text in my first file. This is another line.
To be, or not to be: that is the question:
1234567890 ABC XYZ abc xyz $
Now we are going to see the real power of less with a long file.
$ less file02.txt This is a line of text in my second file. This is another line.
To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? To die: to sleep; No more; and by a sleep to say we end The heart-ache and the thousand natural shocks That flesh is heir to, 'tis a consummation Devoutly to be wish'd. To die, to sleep; To sleep: perchance to dream: ay, there's the rub; For in that sleep of death what dreams may come When we have shuffled off this mortal coil, Must give us pause: there's the respect That makes calamity of so long life; For who would bear the whips and scorns of time, The oppressor's wrong, the proud man's contumely, The pangs of despised love, the law's delay, The insolence of office and the spurns That patient merit of the unworthy takes, When he himself might his quietus make File02.txt
Notice that you are not yet back to the shell prompt. You are still in the less command. You are only one page into the file. less allows you to view long files one page at a time, instead of scrolling them off the top of your screen.
Type the SPACE key to see another page of text.
That patient merit of the unworthy takes,
When he himself might his quietus make With a bare bodkin? who would fardels bear, To grunt and sweat under a weary life, But that the dread of something after death, The undiscover'd country from whose bourn No traveller returns, puzzles the will And makes us rather bear those ills we have Than fly to others that we know not of? Thus conscience does make cowards of us all; And thus the native hue of resolution Is sicklied o'er with the pale cast of thought, And enterprises of great pith and moment With this regard their currents turn awry, And lose the name of action. - Soft you now! The fair Ophelia! Nymph, in thy orisons Be all my sins remember'd.
1234567890 ABC XYZ abc xyz (END)
Notice that you are not yet back to the shell prompt. Even though the entire file contents have been listed, you are still in the less command.
Typing lower case q will quit the less (or more or pg) program.
less (and the other two utility commands) displays one page at a time. This is in contrast with cat, which displays the entire file at once.
Coding example: I am making heavily documented and explained open source code for a method to play music for free almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).
Building a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming.
If you like the idea of this project, then please donate some money.
send donations to: Milo
PO Box 1361
Tustin, California 92781
Supporting the entire project:
If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church)
UNIX used as a generic term unless specifically used as a trademark (such as in the phrase UNIX certified). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.
Names and logos of various OSs are trademarks of their respective owners.