1. more — A Simple Pager
more is one of the simplest and oldest pager utilities in Linux. It allows you to view text files one screen at a time.
Basic Usage:
more filename.txt- It will display the content of
filename.txtone page at a time. - After you reach the end of the screen, it will prompt you for further action.
Navigation with more:
- Spacebar: Move to the next screen of text.
- Enter: Move down one line at a time.
- b: Move backward (one screen).
- q: Quit and exit
more.
While more works for basic file viewing, it is limited in terms of navigation and functionality.
2. less — A More Powerful Pager
less is a more powerful and flexible pager compared to more. It allows you to both scroll forward and backward in the file, which more does not support. It is the pager commonly used by man pages (manual pages) in Linux.
Basic Usage:
less filename.txt- This command will open
filename.txtand allow you to view its contents with much more control over navigation.
Navigation with less:
- Spacebar: Move to the next screen of text (like
more). - Enter: Move down one line at a time.
- b: Move backward one screen.
- q: Quit and exit
less. - Up/Down arrow: Scroll line by line up or down.
- g: Go to the beginning of the file.
- G: Go to the end of the file.
- /search_term: Search for a specific term in the file. Press
nto go to the next occurrence andNto go to the previous occurrence.
Extra Features of less:
- Backward Navigation: You can scroll both forward and backward in the file, unlike
more, which only lets you move forward. - Search: You can search for specific patterns or text inside the file by typing
/search_termand pressing Enter. - Pipe Compatibility:
lessis often used in combination with other commands (using a pipe|), which allows you to scroll through the output of commands that generate large amounts of text.
For example:
dmesg | lessThis command will display kernel messages, which can be quite lengthy, but using less, you can easily navigate through them.
Summary of Differences:
| Feature | more | less |
|---|---|---|
| Forward Navigation | Yes | Yes |
| Backward Navigation | No | Yes |
| Search | No | Yes |
| Scrolling | One screen at a time, limited controls | Line-by-line and screen-by-screen navigation |
| Usage | Simple, older pager utility | More powerful, flexible, and widely used |
In general, less is preferred in most scenarios due to its advanced features and flexibility, but more is still useful for simpler cases when you just need to scroll forward through a file.