less Command in Linux

Learn via video courses
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

The 'less' command in Linux is a powerful utility for viewing text files. Unlike the 'more' command, it allows you to scroll through the file in both forward and backward directions, making it easier to navigate and read large text files. In this article, we'll explore the syntax, options, and common use cases of the 'less' command.

Linux less Command Syntax

The syntax for the less command is as follows:

Where:

  • options: Options are the flags that modify the behavior of the 'less' command.
  • file: The file is the target text file to be viewed using the 'less' command.

less Command Options:

  • -N: Display line numbers at the beginning of each line.
  • -I: Case-insensitive search.
  • -G: Disable colorized output for regular expressions.
  • -X: Do not use termcap initialization and deinitialization strings.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Example Usages

  • View a file using 'less':

    Explanation: Opens the file 'example.txt' and displays its contents, allowing the user to scroll up and down the text.

  • Search for a pattern within a file:

    Explanation: After opening 'example.txt' with 'less', you can search for a pattern by typing '/' followed by the pattern you want to search for, and then press Enter.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Tips

  • You can navigate through the file using the arrow keys, Page Up/Down, or the spacebar.

  • Press 'q' to exit the 'less' command.

Advanced Use Cases of less Command in Linux

  • View multiple files:

    Explanation: Opens both 'file1.txt' and 'file2.txt' in 'less'. You can switch between files using '' for the next file and '

    ' for the previous file.

  • Follow the output of a file in real-time:

    Explanation: Opens 'example.log' and starts following the output in real-time, similar to the 'tail -f' command.

  • View a compressed file:

    Explanation: Opens and decompresses the compressed 'example.gz' file on-the-fly, allowing you to view its contents without manual decompression.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Conclusion

  • The 'less' command is a powerful and flexible text file viewer in Linux.

  • It allows you to navigate through large files easily, both forwards and backwards.

  • You can search for patterns, view multiple files, and even follow output in real-time.