The less command is a powerful tool for viewing text files in Linux. Here’s how to use it:
Basic Usage
- Open a file:
To view a file usingless, use the following command:
Replaceless filename.txtfilename.txtwith the name of the file you want to view.
Navigation Controls
While in the less interface, you can use the following keyboard controls:
- Space: Move forward one page.
- b: Move backward one page.
- Enter: Move forward one line.
- Arrow keys: Navigate up and down line by line.
- g: Go to the beginning of the file.
- G: Go to the end of the file.
- /pattern: Search for a specific text pattern. After typing the pattern, press Enter to find the next occurrence.
- n: Repeat the last search in the same direction.
- N: Repeat the last search in the opposite direction.
- q: Quit
lessand return to the command prompt.
Example
To view a file named sample-file.txt, you would run:
less sample-file.txt
You can then use the navigation controls to explore the file. The less command is particularly useful for large files, as it allows you to view content without overwhelming your terminal screen.
