8. less

Lesson Content

If you are viewing text files larger than a simple output, less is more. (There is actually a command called more that does something similar, so this is ironic.) The text is displayed in a paged manner, so you can navigate through a text file page by page.

Go ahead and look at the contents of a file with less. Once you’re in the less command, you can actually use other keyboard commands to navigate in the file.

$ less /home/pete/Documents/text1

Use the following command to navigate through less:

  • q - Used to quit out of less and go back to your shell.
  • Page up, Page down, Up and Down - Navigate using the arrow keys and page keys.
  • g - Moves to beginning of the text file.
  • G - Moves to the end of the text file.
  • /search - You can search for specific text inside the text document. Prefacing the words you want to search with /
  • h - If you need a little help about how to use less while you’re in less, use help.

Exercise

Run less on a file, then page up and around the file. Try searching for a specific word. Quickly navigate to the beginning or the end of the file.

Quiz Question

# How do you quit out of a less command? > if it’s a large file and you are reading it using any text editor, then the complete file will be loaded to main memory. The less command doesn’t load the entire file, but loads it part by part which makes it faster. 1. [ ] end 2. [ ] :x 3. [ ] exit 4. [x] q