less Linux Command
Views file contents page by page with forward and backward navigation.
What does less do?
Views file contents page by page with forward and backward navigation.
Syntax
less filenamePractical example
less /var/log/syslogQuestions about less
How do I search within less?
Press `/` followed by your search term and Enter to search forward. Press `?` to search backward. Use `n` for next match and `N` for previous.
How do I exit less?
Press `q` to quit less and return to the command prompt. You can also press `:q` to quit.
How do I go to the end of a file in less?
Press `G` (capital G) to jump to the last line of the file. Press `gg` to go to the first line.
How do I scroll down one line in less?
Press the down arrow key or `j` to scroll down one line. Press `k` or the up arrow to scroll up one line.
How do I scroll down one page in less?
Press the spacebar or `f` to scroll forward one page. Press `b` to scroll backward one page.
How do I follow a file that is being written to?
Use `less +F filename` or press `Shift+F` while in less to follow the file in real time (like tail -f). Press Ctrl+C to stop following.
How do I highlight search results in less?
Search results are highlighted by default. If not, use `less -I filename` for case-insensitive highlighting, or press `Esc-U` to toggle highlighting.
Related File Management
catDisplays the entire contents of a file on the terminal.
moreViews file contents one screen at a time (forward-only navigation).
rmdirRemoves an empty directory. Safer than rm -r for removing directories.
headDisplays the first 10 lines of a file by default. Use -n to specify count.
rmRemoves (deletes) files or directories. Use -rf for recursive force delete.
tailDisplays the last 10 lines of a file. Use -f to follow file changes in real time.