Linux/Unix – Paging Through Text
When you have a large chunk of text and need to get to more than just its beginning or end, you need a tool to page through the text. The original Unix system pager was the more command:
$ ps auwx | more —Page through the output of ps (press spacebar)
$ more myfile.txt — Page through the contents of a file
However, more has some limitations. For example, in the line with ps above, more could not scroll up. The less command was created as a more powerful and userfriendly more. The common saying when less was introduced was: “What is less? less is more!” We recommend you no longer use more, and use less instead.
NOTE The less command has another benefit worth noting. Unlike text editors such as vi, it does not read the entire file when it starts. This results in faster start-up times when viewing large files.
The less command can be used with the same syntax as more in the examples above:
$ ps auwx | less —Page through the output of ps
$ cat myfile.txt | less —Page through the contents of a file
$ less myfile.txt — Page through a text file
The less command enables you to navigate using the up and down arrow keys, PageUp, PageDown, and the spacebar. If you are using less on a file (not standard input), press v to open the current file in an editor. Which editor gets launched is determined by environment variables defined for your account. The editor is taken from the environment variable VISUAL, if defined, or EDITOR if VISUAL is not defined. If neither is defined, less invokes the JOE editor on Ubuntu.
NOTE Other versions of Linux invoke vi as the default editor in this case.
Press Ctrl+c to interrupt that mode. As in vi, while viewing a file with less, you can search for a string by pressing / (forward slash) followed by the string and Enter. To search for further occurrences, press / and Enter repeatedly. To scroll forward and back while using less, use the F and B keys, respectively. For example, 10f scrolls forward 10 lines and 15b scrolls back 15 lines. Type d to scroll down half a screen and u to scroll up half a screen.