
pg: View files one page at a time (pager)
pg: View files one page at a time
pg is a simple pager used to display a file or standard input one page at a time. It’s handy when you want to read long files without scrolling continuously.
Quick start
- View a file:
pg {{path/to/file}}
- Display help:
pg {{-h|--help}}
- View a file from stdin (pipe data into pg):
echo "line 1\nline 2" | pg
-
Exit pg: press q
-
Scroll: use the Space bar to go forward a page, or Enter to go one line at a time
What happens under the hood
pg reads the file or input and displays it page by page. It’s similar to more or less but aims for a minimal, straightforward experience. If a file is very large, pg will load and render it in chunks as you navigate.
Common pitfalls
- Not giving pg a file and piping nothing to it: pg will wait for input infinitely. If you meant to view a file, specify the path.
- Example pitfall:
pg
Without input, pg sits idle. If you intended to read from a file, provide the path:
pg /var/log/syslog
- Forgetting to exit: if you’re used to editors, you might try to quit with Ctrl+C. In pg, press q to quit.
- Terminal width issues: very narrow terminals can wrap lines awkwardly. If a file has long lines, you may want to page less or adjust terminal size.
Practical examples
- View a system log page by page:
pg /var/log/syslog
- Read a large text file over SSH without transferring the whole file locally:
ssh user@host 'cat /path/to/largefile' | pg
- Use with pipes to filter output and then page it:
grep -i 'error' /var/log/syslog | pg
Tips for better usage
- Combine with less-like shortcuts: Space to page forward, b to page back (if pg supports it on your version), / to search (depends on build).
- If you want better navigation features, consider using more, less, or a more capable pager, and set the PAGER environment variable accordingly:
export PAGER=less
- Check which pager pg is invoking by inspecting environment variables or man page:
man pg
Troubleshooting
- pg not found: install the package providing pg for your distro (often part of util-linux or a similar util package).
- Behavior differs between systems: some builds of pg support different keybindings. Refer to the help output for your exact build:
pg -h
- If a long file scrolls slowly, ensure your terminal supports the required features (modern terminals generally do). If not, try a more feature-rich pager like less.
Alternatives worth knowing
- less: a more feature-rich pager with search, backward navigation, and many options.
- more: a simpler alternative in many environments.
TL;DR recap
- Use pg to view files page by page: pg path/to/file
- Quit with q; navigate with Space (page) and Enter (line)
- Use stderr/stdout piping to page dynamic output: command | pg
For most quick reads, pg does the job with straightforward keybindings and minimal setup. If you need advanced navigation, consider less or a similar pager.
See Also
- How to Use the test Command in Linux?
- How to Use the grubby Command for Effective Bootloader Management
- How Does the elink Command Enhance Data Cross-Referencing in NCBIs EDirect Suite?
- insmod: Load Kernel Modules
- How Can You Use the i7z Command to Optimize Intel CPU Performance?
- How to Master the ipset Command for Efficient Firewall Management