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:
- View the content of the file by using the command “less filename”, for example: less example.txt
- Scroll down one line by pressing the down arrow key, space bar, or Enter key on the keyboard.
- Scroll up one line: press the up arrow key on your keyboard, or the ‘b’ key.
- Scroll down one screen: press the Page Down key or the space bar on the keyboard.
- Scroll up one screen: Press the Page Up key on the keyboard.
- Jump to the beginning of the file: press the ‘g’ key on the keyboard.
- Jump to the end of the document: press the G key on the keyboard.
- 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.
- To exit the less command: press the q key on the keyboard.
- 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 - 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.