less command in Linux with Examples Last Updated : 03 Nov, 2025 Comments Improve Suggest changes 5 Likes Like Report The less command in Linux is used to view the contents of a file one page at a time without opening it in an editor, making it ideal for reading large files efficiently.It allows you to scroll forward and backward through a file.It does not load the entire file into memory, making it faster for large files.You can search for specific text within the file using /pattern.It provides navigation shortcuts (e.g., Space for next page, b for previous page, q to quit).Commonly used to view log files, configuration files, or command outputs (cat filename | less or less filename)Using 'less' with PipelinesThe less command can also be used in conjunction with other commands through pipelines. This allows us to view the output of a command directly in the less pager.Note: I'm using dmesg output as input to less command in the following examples. For Example: If you want to read the contents of dmesg command, it's better to use it with fewer command dmesg | lessOutput: Syntax:less [options] filenameHere, `filename` represents the name of the file we want to view using the `less` command.The less command provides several options that modify its behavior. Here are some commonly used options:Examples of `less` command in LinuxLet's look at a few examples to illustrate the usage of the less command with different options.1. Searching for a patterndmesg | less -p "fail"The above command tells less to start at first occurrence of pattern "fail" in the file and displaying the file from that point.Output: 2. Displaying line numberdmesg | less -NThe -N option displays line numbers along with the file content, allowing you to reference specific lines easily.Output:3. Checking a small fileless -F /home/Mandeep/test/first.erlIn this example, the file `/home//Mandeep/test/first.erl` is small enough to fit on a single screen. The `-F` option causes less to exit immediately without displaying the file since it can be fully shown in one go.Commonly Used Options in`less`commandHere are the most commonly used and practical options of the less command in Linux:OptionsDescription-EAutomatically exit when reaching the end of the file.-fForce non-regular files to be opened.-FExit if the entire file can be displayed on the first screen.-gHighlight the string that was found by the last search command.-GSuppress highlighting of search matches.-iIgnore cases when searching.-nSuppress line numbers.-p patternStart at the first occurrence of the specified pattern in the file.-sSqueeze consecutive blank lines into a single line. Create Quiz Comment M msdeep14 Follow 5 Improve M msdeep14 Follow 5 Improve Article Tags : Misc Linux-Unix linux-command Linux-text-processing-commands Explore Getting Started with LinuxIntroduction to Linux Operating System7 min readLINUX Full Form - Lovable Intellect Not Using XP2 min readDifference between Linux and Windows7 min readLinux Distributions6 min readDifference between Unix and Linux6 min readInstallation with LinuxInstallation of Arch Linux in VirtualBox4 min readFedora Linux Operating System5 min readHow to install Ubuntu on VirtualBox?6 min readHow to Install Linux Mint?3 min readInstallation of Kali Linux in Virtual Machine2 min readHow to Install Linux on Windows PowerShell Subsystem?2 min readHow to Find openSUSE Linux Version?2 min readInstallation of CentOS2 min readLinux CommandsLinux Commands15+ min readEssential Unix Commands7 min readFind Command in Linux with Examples7 min readLinux File SystemLinux File System12 min readLinux File Hierarchy Structure5 min readLinux Directory Structure6 min readLinux KernelLinux Kernel4 min readKernel in Operating System3 min readHow Linux Kernel Boots?11 min readDifference between Operating System and Kernel3 min readLinux Kernel Module Programming: Hello World Program7 min readLinux Loadable Kernel Module7 min readLoadable Kernel Module - Linux Device Driver Development4 min readLinux Networking ToolsNetwork configuration and troubleshooting commands in Linux5 min readHow to configure network interfaces in CentOS?5 min readCommand-Line Tools and Utilities For Network Management in Linux8 min readLinux - Network Monitoring Tools4 min readLinux ProcessProcesses in Linux/Unix5 min readHow to Manage Process in Linux4 min readGetting System and Process Information Using C Programming and Shell in Linux2 min readProcess states and Transitions in a UNIX Process4 min readLinux FirewallLINUX Firewall7 min readiptables command in Linux with Examples7 min readHow to Configure your Linux Firewall - 3 Methods12 min readShell Scripting & Bash ScriptingIntroduction to Linux Shell and Shell Scripting7 min readUnderstanding Terminal, Console, Shell and Kernel3 min readHow to Create a Shell Script in linux7 min readShell Scripting - Different types of Variables4 min readBash Scripting - Introduction to Bash and Bash Scripting12 min readBash Script - Define Bash Variables and its types12 min readShell Scripting - Shell Variables6 min readBash Script - Difference between Bash Script and Shell Script4 min readShell Scripting - Difference between Korn Shell and Bash shell3 min readShell Scripting - Interactive and Non-Interactive Shell3 min readShell Script to Show the Difference Between echo â$SHELLâ and echo â$SHELLâ4 min readLinux Administrator SystemWhat is Linux System Administration?6 min readBeginner's Guide to Linux System Administration5 min readHow to Monitor System Usage, Outages and Troubleshoot Linux Servers6 min readLinux - Systemd and its Components3 min readBoot Process with Systemd in Linux3 min readHow to Control Systemd Services on Remote Linux Server2 min readHow to Start, Stop and Restart Services in Linux Using systemctl Command9 min read Like