less Command: Tutorial & Examples
View the contents of a file one page at a time
The less
command is a utility that is used to view text files in a terminal window. It allows you to scroll through the file one page at a time, search for specific text within
the
file, and navigate to specific lines or locations within the file.
To view a file with less, simply type less followed by the name of the file:
less file.txt
This will open the file in less
and display the first page of the file. You can use the up and down arrow keys to scroll through the file, or the space bar to move forward one
page
at a time. You can also use the /
key followed by a search term to search for specific text within the file.
/search_term
To go to a specific line number within the file, you can use the g
key followed by the line number:
g100
This will go to line number 100 in the file.
less
is often used in conjunction with other commands, such as grep
or tail
, to filter and process the output of those commands
before viewing it in less. For example, you can use less
to view the /var/log/messages
file by piping the output of cat
to less
:
cat /var/log/messages | less
less
is a powerful and flexible tool for viewing and navigating text files on a Linux system. It is often used as an alternative to the more
command,
which has fewer features and is less powerful.