0
0
Linux CLIscripting~5 mins

less and more (paginated viewing) in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes files or command outputs are too long to fit on one screen. The tools less and more help you view this content page by page, making it easier to read without scrolling endlessly.
When you want to read a long log file without it scrolling past too fast.
When you run a command that outputs many lines and you want to see it bit by bit.
When you need to search inside a long text output interactively.
When you want to pause and resume reading a file at your own pace.
When you want to scroll backward and forward through command output.
Commands
This command opens the syslog file in less, allowing you to scroll through the file page by page. You can move forward with spacebar and backward with 'b'.
Terminal
less /var/log/syslog
Expected OutputExpected
No output (command runs silently)
This command opens the syslog file in more, which also shows the file page by page but has fewer navigation features than less.
Terminal
more /var/log/syslog
Expected OutputExpected
No output (command runs silently)
This pipes the output of dmesg (kernel messages) into less so you can scroll through the messages easily.
Terminal
dmesg | less
Expected OutputExpected
No output (command runs silently)
This pipes the content of syslog through more, showing it page by page. Useful if you want to combine commands with paginated viewing.
Terminal
cat /var/log/syslog | more
Expected OutputExpected
No output (command runs silently)
Key Concept

If you remember nothing else from this pattern, remember: less is a more powerful pager than more, letting you scroll both forward and backward through long text outputs.

Common Mistakes
Using cat to view a long file without a pager (e.g., cat /var/log/syslog)
The output scrolls past too fast to read, making it hard to see the content.
Use less or more to view the file page by page for easier reading.
Using more when you need to scroll backward
more does not support backward scrolling, so you cannot go back to previous pages.
Use less which supports both forward and backward navigation.
Summary
Use less or more to view long files or command outputs page by page.
less allows both forward and backward scrolling, while more only allows forward.
You can pipe command outputs into less or more to read them easily.