Command Line · Lesson 8 of 19
less
0 / 5 checkpoints answered
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.
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.
CheckWhich command opens /var/log/syslog in an interactive pager?
press 1/2/3 to answer · → next lesson
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.
CheckWhich key jumps directly to the end of a file in less?
press 1/2/3 to answer · → next lesson
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.
CheckAfter a forward search for error, which key repeats the search in the same direction?
press 1/2/3 to answer · → next lesson
Leaving less
Press q to quit less and return to the shell prompt.
CheckWhich key exits less and returns to the shell?
press 1/2/3 to answer · → next lesson
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
CheckWhich command opens /var/log/syslog and follows new content as it arrives?
press 1/2/3 to answer · → next lesson
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.
Summary
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.
Lesson complete
You finished less. Nice work — keep the momentum going.