How to use the SSH less command

The less command displays file contents one screen at a time, unlike cat which dumps everything at once. In particular, less is better for large files like logs, configs, or exports because you can scroll forward and backward without loading the whole file into memory. Furthermore, less supports search, line numbers, and piping from other commands, making it the standard pager for viewing text on Linux servers via SSH.

View a file

To open a file in less:

less myTextFile.txt

Example: less error_log or less ~/public_html/wp-config.php. The file opens in pager mode. Use the keyboard to navigate.

Use less with a pipe

To view output from another command one screen at a time:

cat largeTextFile.txt | less

Or pipe directly from commands: grep "error" error_log | less, tail -1000 access_log | less. Useful when output is long.

Navigation shortcuts

While in less, you are in pager mode. Common keys:

  • Space or Page Down: next page
  • b or Page Up: previous page
  • Down arrow or j: next line
  • Up arrow or k: previous line
  • / then type and Enter: search forward
  • n: next search match, N: previous match
  • g: go to start, G: go to end
  • q: quit and return to the shell

For all options, run less --help or press h while in less.

Show line numbers

To display line numbers:

less -N error_log

Or press -N then Enter while viewing to toggle. Helps when referencing specific lines.

When to use less vs cat

Use cat for small files or when you need to pipe output to another command. Use less when the file is large or you want to scroll and search. For only the first or last lines, use head or tail. See our guides on the SSH cat command and head and tail.

Common use cases

Typical uses for SSH less command on a Linux hosting account:

  • Viewing error logs or access logs without flooding the terminal
  • Inspecting large config files or exports
  • Searching through log output for specific messages or IPs
  • Browsing command output that is too long for one screen

Need more help?

Explore more SSH and hosting guides in our knowledgebase. JetHost web hosting includes SSH access for managing your server files directly.