Skip to content

What is less Linux command?

The Linux less command is a powerful tool for viewing file contents in the terminal efficiently. It allows users to navigate through text files, search for specific content, and analyze lengthy documents with ease.

Terminal window
less [option] [file]
OptionDescription
-NDisplay line numbers
-iIgnore case when searching
-STruncate long lines
-FQuit immediately if entire file can be displayed
-h, —helpDisplay help message
ParameterDescription
fileThe file to be viewed
Terminal window
less file.txt

The command displays the contents of the “file.txt” for ease of reading.

Terminal window
less file.txt

To scroll down a file, press the “Space” (PgDn) key.

Terminal window
less file.txt

To scroll up a file, press the “b” (PgUp) key.

Terminal window
less file.txt

To search for a specific string within a file, type “/search_term” followed by Enter.

Terminal window
less file.txt

To jump to a specific line number within a file, type the line number followed by “g” and Enter.

To use the less command in bash, execute the following command:

Terminal window
less file.txt

How can I search for a specific text in a file using less?

Section titled “How can I search for a specific text in a file using less?”

To search for a specific text in a file using less, input the following command:

Terminal window
less file.txt
/pattern

How can I navigate to the end of a file quickly with less?

Section titled “How can I navigate to the end of a file quickly with less?”

To navigate to the end of a file quickly with less, type the following command:

Terminal window
less file.txt
Shift + G

How can I display line numbers while viewing a file with less?

Section titled “How can I display line numbers while viewing a file with less?”

To display line numbers while viewing a file with less, run the command:

Terminal window
less -N file.txt

How can I view multiple files in less with a single command?

Section titled “How can I view multiple files in less with a single command?”

To view multiple files in less with a single command, use the following syntax:

Terminal window
less file1.txt file2.txt

How do I open a file with less in read-only mode?

Section titled “How do I open a file with less in read-only mode?”

To open a file with less in read-only mode, use the following command:

Terminal window
less -R file.txt

How can I navigate horizontally in less when viewing a file with long lines?

Section titled “How can I navigate horizontally in less when viewing a file with long lines?”

To navigate horizontally in less when viewing a file with long lines, execute the following command:

Terminal window
less -S file.txt

How do I exit less without viewing the entire file?

Section titled “How do I exit less without viewing the entire file?”

To exit less without viewing the entire file, simply use the following command:

Terminal window
less +G file.txt
  • Viewing the contents of a file
  • Navigating through a file
  • Searching for specific text within a file
  • Handling large files more efficiently than with cat command
  • Allowing for backward navigation through a file