How to View Large Files in Linux Using less

In Linux, the standard command for viewing text files is cat. However, cat is a “dumb” command; it simply takes the entire contents of a file and dumps it into your terminal as fast as possible. If you use cat on a tiny three-line configuration file, it works perfectly. But if you use cat on a massive 10,000-line server error log, the terminal will rapidly scroll past 9,970 lines of text in half a second, leaving you staring at only the very bottom of the file. You will not be able to read anything, and you will lose your place in the terminal. When dealing with massive amounts of data, you must use a terminal “pager” program. The most powerful and widely used pager in Linux is less.

What Makes ‘less’ Superior

Instead of dumping the text and returning you to the command prompt, less takes over the terminal screen entirely. It creates an interactive reading environment. It loads the file instantly (even if the file is gigabytes in size, because it doesn’t load the whole file into RAM at once), displays only the first page of text that fits on your physical screen, and pauses, waiting for you to tell it what to do next.

Step-by-Step: Viewing a File with less

  1. Open your Linux terminal.
  2. Type the command followed by a space and the name of your file. For example: less /var/log/syslog
  3. Press Enter.

Your command prompt will disappear, and the terminal will fill with the first few dozen lines of the file. Notice the bottom-left corner of the screen; it will either show the file name or a blinking cursor, indicating less is active and waiting for your commands.

Navigating Inside the File

Because less is an interactive environment, you must use specific keyboard commands to move around. You cannot use your mouse scroll wheel effectively.

  • Move Down One Line: Press the Down Arrow key (or the ‘j’ key).
  • Move Up One Line: Press the Up Arrow key (or the ‘k’ key).
  • Move Down One Full Page: Press the Spacebar (or Page Down). This is the fastest way to read through a long document.
  • Move Up One Full Page: Press the ‘b’ key (for ‘backward’, or Page Up).
  • Jump to the Beginning: Press ‘g’ (lowercase).
  • Jump to the Very End: Press ‘G’ (uppercase Shift+G). This is incredibly useful for checking the most recent entries in a log file.

Searching for Text

The true power of less is its built-in search engine, which allows you to find specific errors in a sea of data instantly.

  1. While viewing a file in less, press the forward slash key ( / ).
  2. A slash will appear at the bottom of the screen. Type the word you are looking for (e.g., /error or /failed).
  3. Press Enter.
  4. less will instantly jump to the first occurrence of that word and highlight it on the screen.
  5. To find the next occurrence of that same word further down the file, simply press the ‘n’ key (for ‘next’). Press ‘N’ (Shift+N) to search backward up the file.

The Most Important Command: Exiting

Beginners often get trapped inside the less environment because standard commands (like typing ‘exit’ or hitting Ctrl+C) do not always work as expected. When you are finished reading the file and want your normal command prompt back, simply press the ‘q’ key (for ‘quit’). less will immediately close, the file text will vanish, and you will be returned to your standard terminal workspace.

Get the best tech tips delivered straight to your inbox.

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