When a text file is too long for one screen, less lets you read it without sending the entire file scrolling through the terminal. Its name inspired the old Unix joke, "less is more," because more is another pager.
Command Line · Lesson 8
less
Learn how to navigate, search, and follow long text files interactively with less.
Opening a File
Start the pager by passing it a filename:
$ less /home/pete/Documents/text1
While less is active, keystrokes control the pager rather than starting ordinary shell commands. You return to the shell when you quit the pager.
Which command opens /var/log/syslog in an interactive pager?
Navigating in less
Use these keys while the pager is open:
- Use
Up,Down,Page Up, andPage Downto move by lines or screens. - Press
gto jump to the beginning. - Press
Gto jump to the end. - Press
uto move up half a screen ordto move down half a screen. - Press
hto open the built-in help.
Which key jumps directly to the end of a file in less?
Searching in less
Type / followed by a pattern and press Enter to search forward. Begin with ? to search backward.
/search_term: Search forward forsearch_term.?search_term: Search backward forsearch_term.n: Repeat the search in the same direction.N: Repeat the search in the opposite direction.
After a forward search for error, which key repeats the search in the same direction?
Leaving less
Press q to quit less and return to the shell prompt.
Which key exits less and returns to the shell?
Starting less with Options
Options and initial commands can change how the pager starts:
$ less -N file.txt
$ less +G file.txt
$ less +F /var/log/syslog
-N: Show line numbers.+G: Open at the end of the file.+F: Follow new content as it is added, similar totail -f.
While following a file with +F, press Ctrl+C to stop following and return to normal navigation, then press q to quit. Use -i for searches that ignore case unless the pattern contains an uppercase letter, or -I to ignore case regardless of the pattern.
Commands can also send output through a pipe to less:
$ dmesg | less
Which command opens /var/log/syslog and follows new content as it arrives?
To practice paging, searching, and reading system text, try these hands-on labs:
- Linux less Command: File Paging - Learn the Linux 'less' command for efficient text file viewing and navigation, including search, line numbers, and pattern matching.
- Viewing Log and Configuration Files in Linux - Learn essential Linux command-line skills for efficiently viewing and navigating text files, including system logs and configuration files, using commands like
cat,more, andless.
Lesson complete
You finished less
You can now use less to inspect long files without flooding the terminal.
Open a file or piped command output in the pager.
Navigate to specific parts of the input.
Search forward or backward and repeat a search.
Show line numbers or follow growing content.
Quit safely and return to the shell.
Keep your learning progress
Create a free account to save this lesson and continue learning on any device.
Create a free account