• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

The Less Command: The Complete Guide

Benjamin O'Donald

Published on: March 4, 2025

Categories: Linux Command Line 0

Table of Contents
  • What is the less command in Linux?
  • Basic syntax for the less command in Linux
  • Common flags/options for the less command in Linux
  • Using the less help option
  • Helpful keys to know while using the less command in Linux
  • Viewing file contents using the less command in Linux
    • Basic viewing of files using the less command in Linux
    • Showing line numbers while viewing files using the less command in Linux
    • Searching for strings while viewing files with the less command in Linux
    • Open a text file with a specified search pattern
    • Open multiple files with the less command in Linux
  • Piping other commands into the less command in Linux
    • Piping other commands into less (example 1)
    • Piping other commands into less (example 2)
  • Conclusion

What is the less command in Linux?

Ever heard the expression “less is more”? Well today we’ll be going over the less command in Linux which is very similar to another command called “more”.

Less is a Linux command line tool available on all Linux operating systems and it allows you to page/search through log file output or file contents in pages.

The functionality offered with the less command is extremely useful as you can search forward or backwards for specified strings through multiple files/logs at a time.

Within this article we’ll cover the basics to get you started using the less command and provide quite a few examples of its usage.

Basic syntax for the less command in Linux

The general syntax for using less on the command line interface is as follows:

$ less [flags] example-file.txt
$ less [flags] example-log-file.log

Common flags/options for the less command in Linux

Below is a list of command flags/options which can be used with the less command:

  • -E Have the command exit once the end of the output is reached
  • -f Using force to open non-regular files such as directories
  • -F Have the command exit if the entire file or output can displayed in a single page
  • -i Ignore case sensitivity
  • -n Remove the line numbers from output in screen
  • -p Have the command to start at the first instance of a pattern you’re searching for
  • -X Don’t clear the screen/page after quitting the less command

Using the less help option

You can always review the man pages for less or use the following to see all other options available with less on the Linux command line:

$ less --help

Helpful keys to know while using the less command in Linux

KeysFunctionality
Down Arrows, Enter, e, jMove one line forward
Up Arrow, y, kMove on line backward
Space Bar, Page DownScroll forward one page
Page up, bScroll backward one page
Left ArrowScroll to the left
Right ArrowScroll to the right
Home, gGo to beginning of output
End, GGo to end of output in file contents
nMove to next string match in search (forward search)
NMove to previous string match in search (backward search)
qExit

Viewing file contents using the less command in Linux

Basic viewing of files using the less command in Linux

To view file contents or even log files with less you can simply use the following command syntax in the command prompt:

$ less example-file.txt

When doing so you’ll be able to scroll forward through the entire files contents:

From the above command we’d see output such as in the following screen shot:

And if we hit the “end” key we can skip to the bottom (last line) of the files contents:

All other key shortcuts mentioned in the sections above can be utilized to view entire file contents such as if we wanted to scroll back up using the Up Arrows for moving up one line at a time, or Page Up button to view previous page of output.

Alternatively you can use the Down Arrow to move downward one line at a time, Page Down button to scroll down an entire page, or space bar to scroll forward.

Showing line numbers while viewing files using the less command in Linux

Just as in the previous section we can utilize another one of the flags mentioned to show line numbers within the same file using the following on the command line:

$ less -N example-file.txt

And the command output while using the above less command on this file would look like the following while utilizing -N as a flag:

Searching for strings while viewing files with the less command in Linux

At times it may be needed to look for certain strings through entire files and we can do so using the less command.

To do so, we would enter the file with less and then once we are within the file we would use / followed by the desired search string.

In this example we’re using /define and we’ll see how it highlights lines with that string through the entire file:

After typing in /define we would see the following string become highlighted:

From here we could use n to search forward within the file for each instance of the specified string or N to backward search.

Open a text file with a specified search pattern

Expanding off the previous example we can also open a file with less to find a specified string or search match pattern with the following command in the command prompt:

$ less -pdefine functions.php

The command output would be the same as if we were using /define within the less search while inside the file (like in the previous example) and we’re able to move through the file to each instance of that specified string:

Open multiple files with the less command in Linux

With the less command you’re not just limited to using it on one file at a time and are actually able to run the command on multiple files at a time.

To use less on multiple files you would use the following syntax as example:

$ less functions.php header.php

When opening multiple files with less you move between the two files by entering in the following key which will bring you to the next file to view its contents:

:n

As example in the screen shot below we see how at the bottom of the file (highlighted section) that we have multiple files selected in the less command and we’re currently in file 1 of 2:

Now after entering in ‘:’ followed by ‘n’ we can move from the current file to the next file as shown below:

If you’d like to return back to the previous file you would just need to press ‘:’ followed by ‘p’.

:p

Piping other commands into the less command in Linux

To make your searches even more friendly to the eyes you can pipe other commands into less.

Piping other commands into less (example 1)

For example, lets say we’re browsing through the Apache error log and want to use less but only show output for log entries in reference to a specific IP address.

In such a case we could use the following command syntax in our terminal window to browse through the contents of that log file wherever the IP is referenced:

$ less /var/log/apache2/error_log | grep IP.Address.Goes.Here

This would browse through the Apache error log for instances of where that IP is referenced and with less we can scroll through the output page by page such as we’ve gone over previously.

Piping other commands into less (example 2)

In this example we’re going to be looking into all IP addresses which have been hitting an example website for a specific day and use less to page through the output:

$ grep -s "25/Feb/2025:1" /var/log/apache2/domlogs/* | awk '{print $1}' | cut -d: -f1 | sort | uniq -c | sort -rn | less

From the above we’d obtain command output of grepping for IP requests taking place on Feb. 25th of 2025 through the Apache Domlogs (traffic logs) and we’d print out each IP address to show the number of hits each IP made on that specific date.

By adding less into the command we can scroll through the output page by page and start from the beginning of output.

Conclusion

The less command in Linux offers loads of functionality and is a very popular command line tool which is utilized by Linux Administrators.

With less being offered on all Linux operating systems it is important to learn how to incorporate less either by itself as a command or with other commands on the Linux command line interface.

Through out this article we have covered quite a bit on the less command in Linux to help get you started and provided examples to show-case basic usage of its functionality.

Related Posts

Symbolic Links vs Hard Links in Linux

Linux offers various methods for referencing files and directories through other files and directories, without creating copies of the original. If you have color coding enabled in your bash terminal, you might have seen some folders full of files of a different color from regular files. There’s a good chance that these are all symbolic […]

Curl Headers, Cookies, and Authentication

You can do a lot more with curl, than just sending requests. Here's how to change the headers, the cookies, and how to authenticate users.

Docker Build Cache – How it Works and Invalidating it

Docker heavily optimizes its build process with caching to save time. But it's important to know how to invalidate it.

How Curl Follows Redirects on Linux

We use curl regularly to fetch resources from websites. Unfortunately, curl doesn't follow redirects automatically. Here's how to fix that.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA