less file1The cat command is useful, but if you're trying to read a long file, it's not useful at all because text just flows past in an unending, unreadable stream. If you're interested in viewing a long file on the command line (and by "long," think more than a page or two), you don't want cat; you want less. The less command is an example of a pager, a program that displays text files one page at a time. Others are more, pg, and most; in fact, less was released back in 1985 as an improved more, proving once again that less is more! Opening a file with lesseven an enormous one like Milton's Paradise Lostcouldn't be easier: $ less Paradise_Lost.txt The less command takes over your entire screen, so you have to navigate within less using your keyboard, and you have to quit less to get back to the command line. To navigate inside less, use the keys in Table 5.1:
As you can see, you have many options for most commands. Probably the two you'll use most often are those used to move down a page at a time and quit the program. To view information about the file while you're in less, press =, which displays some data at the very bottom of your screen similar to the following: Paradise_Lost.txt lines 7521-7560/10762 byte 166743/237306 70% (press RETURN) As you can see, you're helpfully told to press Enter to get rid of the data and go back to using less. In the same way that you could tell cat to stick in line numbers for a file, you can also order less to display line numbers. Those numbers only appear, of course, while you're using less. After you press q, the numbers are gone. To view the file, but with numbers at the start of each line, start less with the -N (or --LINE-NUMBERS) option, and yes, you must use all caps: $ less -N Paradise_Lost.txt |