How to exit the “less” command in Linux?

To exit while browsing a file using the less command in the terminal, you can follow these steps:

First, you need to open the terminal and run the “less” command to view the file. For example, to view a text file named file.txt, you can input the following command:

   less file.txt

Once the file is opened in less mode, you can use the following keyboard shortcuts to operate:

Scroll through the contents of the file using the up arrow (↑) and down arrow (↓).

Scroll horizontally within a line using the left arrow (←) and right arrow (→).

Press the space bar to scroll one page forward.

Pressing the B key will scroll back one page.

Enter a search string to find specific text.

Pressing the G key will take you to the end of the file.

Press the H key to display help information for more shortcut keys related to operations.

To exit less and return to the terminal prompt, simply press the capital letter Q. Note that the Q here is uppercase.

Once you press the Q key, less will exit immediately, and you will return to the terminal prompt, where you can continue with other operations.

These are the detailed steps on how to use the less command and exit in Linux.

bannerAds