How to Use the less Command in Linux

The less command is a must-know tool for Linux users, offering a lightweight way to view text files or command outputs one screen at a time. Perfect for browsing large logs or configuration files without editing them, less is fast, efficient, and beginner-friendly. This guide enhances your understanding with practical examples and tips to master less on your Linux system, whether you’re managing a VPS or debugging logs.

What Does less Do?

When you open a file with less, it doesn’t load the entire file into memory. Instead, it streams the content as you scroll, which makes it very fast and lightweight — even with log files that are several megabytes in size. Unlike text editors like nano or vim, less is non-editable — it’s strictly for reading. This means you can safely open configuration files, logs, or any text file without the risk of accidentally modifying them.

Syntax and Basic Usage

less [options] filename

Example:

less /var/log/auth.log

This will open the system authentication log in less, allowing you to navigate through it with simple key commands.

Key Navigation Commands in less

KeyFunction
SpaceScroll forward one page
bScroll backward one page
EnterScroll down one line
gGo to the beginning of the file
GJump to the end of the file
/patternSearch forward for a keyword (e.g. /error)
n / NRepeat search (next/previous match)
qExit less

These commands make it easy to review logs, search for specific entries, or simply browse through structured files.

Practical Examples

Example 1: View a large configuration file

less /etc/ssh/sshd_config

Quickly check SSH settings without accidentally changing anything.

Example 2: View system logs with search

less /var/log/syslog

Then press /fail to search for lines containing “fail”.

Example 3: Use less with another command

ps aux | less

View the full output of the ps aux command without it scrolling off the screen.

Options Worth Knowing

  • -N — Show line numbers:

    less -N /etc/passwd
  • -S — Chop long lines instead of wrapping them:

    less -S /var/log/dpkg.log
  • +G — Open file and jump straight to the end:

    less +G /var/log/mysql/error.log

These options enhance how you interact with files in various contexts — from debugging errors to verifying recent log entries.

Extra Tip: Work with Compressed Files

You can read .gz files without extracting them using zless, a variation of less:

zless /var/log/syslog.1.gz

It behaves exactly like less, but works with compressed content — ideal for archived logs.

Conclusion

The less command is a versatile, lightweight tool that simplifies viewing and navigating text files or command outputs in Linux. With its read-only nature, efficient memory use, and powerful search capabilities, it’s perfect for managing logs, configs, or piped outputs. The examples and tips above help you leverage less for quick debugging or system management, making it an essential part of your Linux toolkit.