How to View the Contents of a File Page by Page Using the less Command in Ubuntu Linux

If you use the standard cat command to read a text file in the Ubuntu Linux terminal, it dumps the entire contents of the file onto your screen instantaneously. If the file is only five lines long, this is perfectly fine. However, if you are trying to read a server log file that contains ten thousand lines, the text will violently scroll past your eyes in a blur, leaving you staring at the very bottom of the document. To read large files comfortably at your own pace, you should use the less command.

What Does the less Command Do?

The less command is a terminal pager. Instead of dumping the entire file at once, it opens the file and displays only the first “page” (exactly the amount of text that fits vertically inside your current terminal window). It then pauses and waits for your input, allowing you to scroll through the document line by line or page by page. Importantly, it does not load the entire massive file into system RAM all at once, making it incredibly fast and efficient for opening gigabyte-sized log files.

How to Use the less Command

To open a file, simply type the command followed by the filename:

less my_large_file.txt

Your terminal screen will clear, and the first page of the text document will appear. You will see a blinking cursor at the bottom left of the screen, indicating that the command is active and waiting for your instructions.

Keyboard Navigation Shortcuts

Once inside the less viewer, you cannot use your mouse scroll wheel in older terminal environments. You must navigate using your keyboard.

  • Scroll Down One Line: Press the Down Arrow key (or the j key).
  • Scroll Up One Line: Press the Up Arrow key (or the k key).
  • Scroll Down One Full Page: Press the Spacebar (or the Page Down key).
  • Scroll Up One Full Page: Press the b key (for “backward”) or the Page Up key.
  • Jump to the End of the File: Press capital G.
  • Jump to the Beginning of the File: Press lowercase g.

Searching for Text

You can also search for specific words or phrases while inside the viewer.

  1. Type a forward slash (/). You will see it appear at the bottom of the screen.
  2. Type the word you want to find (e.g., /error) and press Enter.
  3. The screen will instantly jump to the first occurrence of that word.
  4. To jump to the next occurrence of the same word, press the lowercase n key.
  5. To search backward, press the uppercase N key.

How to Exit

The most common mistake beginners make is not knowing how to close the viewer. You cannot type standard commands while less is active.

To close the file and return to your normal command prompt, simply press the q key (for “quit”).

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.