Linux less Command

Rahul Ahir
2 min readMay 27, 2023

--

The less command is a text file viewer in Linux and Unix-like operating systems. It allows you to view the contents of a file interactively, scrolling through its contents in a controlled manner. The less command is often used to view large files, as it loads the file in chunks rather than loading the entire file into memory.

Here’s how the less command works:

  1. Open the terminal: Launch a terminal window on your Linux system.
  2. Basic usage: To view a file using less, simply type less followed by the name of the file you want to view. For example, if you want to view a file called "myfile.txt," you would run the command less myfile.txt. Press Enter to execute the command.
  3. Navigation: Once the file is open in less, you can navigate through its contents using various commands:
  • Use the arrow keys to scroll up and down line by line.
  • Press the Spacebar to scroll down one page at a time.
  • Press the Backspace key to scroll up one page at a time.
  • Type a forward slash (“/”) followed by a search term to search for a specific word or pattern within the file. Press Enter to search, and less will highlight the matching results.
  • Press “n” to move to the next occurrence of the search term.
  • Press “N” (Shift + n) to move to the previous occurrence of the search term.
  • Press “g” to go to the beginning of the file.
  • Press “G” (Shift + g) to go to the end of the file.

4. Quitting less: To exit the less viewer and return to the terminal, press the "q" key.

The less command provides a convenient way to view and navigate through the contents of text files without overwhelming system resources. It is particularly useful when dealing with large log files, configuration files, or any other lengthy text-based documents.

--

--

Rahul Ahir

YouTuber @ahirlog | Flutter Developer | Digital Creator