What is the usage of the “less” command in Linux?

The less command in Linux is used to view the contents of a text file, allowing you to browse the file one page at a time without loading the entire file into memory. Here are some common uses of the less command:

  1. View the content of the file by using the command “less filename”, for example: less example.txt
  2. Scroll down one line by pressing the down arrow key, space bar, or Enter key on the keyboard.
  3. Scroll up one line: press the up arrow key on your keyboard, or the ‘b’ key.
  4. Scroll down one screen: press the Page Down key or the space bar on the keyboard.
  5. Scroll up one screen: Press the Page Up key on the keyboard.
  6. Jump to the beginning of the file: press the ‘g’ key on the keyboard.
  7. Jump to the end of the document: press the G key on the keyboard.
  8. Search keywords: Press the / key on the keyboard, then type in the keywords you want to search for, and press enter. Use the n and N keys to navigate between search results.
  9. To exit the less command: press the q key on the keyboard.
  10. Display line numbers: When using the less command, you can use the -N option to show line numbers, the command is as follows:
    less -N filename
    For example: less -N example.txt
  11. When using the less command, you can use the -S option to disable line wrapping when lines are too long, the command is as follows:
    less -S filename
    For example: less -S example.txt

Please note that the filename in the above command can be either an absolute path or a relative path.

bannerAds